on master help sign in
Add basic support for the loopback construct
5018b35Evan Czaplicki
src/AST/Declaration.hs+56−36
@@ -11,11 +11,11 @@ import AST.PrettyPrint
11import Text.PrettyPrint as P
11import Text.PrettyPrint as P
12
12
13
13
14−data Declaration' port def var
14+data Declaration' wire def var
15 = Definition def
15 = Definition def
16 | Datatype String [String] [(String, [T.Type var])]
16 | Datatype String [String] [(String, [T.Type var])]
17 | TypeAlias String [String] (T.Type var)
17 | TypeAlias String [String] (T.Type var)
18− | Port port
18+ | Wire wire
19 | Fixity Assoc Int String
19 | Fixity Assoc Int String
20
20
21
21
@@ -23,34 +23,38 @@ data Assoc = L | N | R
23 deriving (Eq)
23 deriving (Eq)
24
24
25
25
26−data RawPort
26+data RawWire
27 = InputAnnotation String T.RawType
27 = InputAnnotation String T.RawType
28 | OutputAnnotation String T.RawType
28 | OutputAnnotation String T.RawType
29+ | OutputDefinition String Source.Expr
30+ | LoopbackAnnotation String T.RawType
29− | OutputDef String Source.Expr
31+ | LoopbackDefinition String Source.Expr
30
32
31
33
32−data Port expr var
34+data Wire expr var
33− = Out String expr (T.Type var)
35+ = Output String expr (T.Type var)
34− | In String (T.Type var)
36+ | Input String (T.Type var)
37+ | Loopback String (Maybe expr) (T.Type var)
35
38
36
39
37type SourceDecl =
40type SourceDecl =
38− Declaration' RawPort Source.Def Var.Raw
41+ Declaration' RawWire Source.Def Var.Raw
39
42
40
43
41type ValidDecl =
44type ValidDecl =
42− Declaration' (Port Valid.Expr Var.Raw) Valid.Def Var.Raw
45+ Declaration' (Wire Valid.Expr Var.Raw) Valid.Def Var.Raw
43
46
44
47
45type CanonicalDecl =
48type CanonicalDecl =
46− Declaration' (Port Canonical.Expr Var.Canonical) Canonical.Def Var.Canonical
49+ Declaration' (Wire Canonical.Expr Var.Canonical) Canonical.Def Var.Canonical
47
50
48
51
49−portName :: Port expr var -> String
52+wireName :: Wire expr var -> String
50−portName port =
53+wireName wire =
51− case port of
54+ case wire of
52− Out name _ _ -> name
55+ Input name _ -> name
56+ Output name _ _ -> name
53− In name _ -> name
57+ Loopback name _ _ -> name
54
58
55
59
56assocToString :: Assoc -> String
60assocToString :: Assoc -> String
@@ -82,8 +86,8 @@ instance Binary Assoc where
82
86
83-- PRETTY STRINGS
87-- PRETTY STRINGS
84
88
85−instance (Pretty port, Pretty def, Pretty var, Var.ToString var) =>
89+instance (Pretty wire, Pretty def, Pretty var, Var.ToString var) =>
86− Pretty (Declaration' port def var) where
90+ Pretty (Declaration' wire def var) where
87 pretty decl =
91 pretty decl =
88 case decl of
92 case decl of
89 Definition def -> pretty def
93 Definition def -> pretty def
@@ -109,7 +113,7 @@ instance (Pretty port, Pretty def, Pretty var, Var.ToString var) =>
109 name' =
113 name' =
110 P.text name <+> P.hsep (map P.text tvars)
114 P.text name <+> P.hsep (map P.text tvars)
111
115
112− Port port -> pretty port
116+ Wire wire -> pretty wire
113
117
114 Fixity assoc prec op ->
118 Fixity assoc prec op ->
115 P.text "infix" <> assoc' <+> P.int prec <+> P.text op
119 P.text "infix" <> assoc' <+> P.int prec <+> P.text op
@@ -121,32 +125,48 @@ instance (Pretty port, Pretty def, Pretty var, Var.ToString var) =>
121 R -> P.text "r"
125 R -> P.text "r"
122
126
123
127
124−instance Pretty RawPort where
128+instance Pretty RawWire where
125− pretty port =
129+ pretty wire =
126− case port of
130+ case wire of
127 InputAnnotation name tipe ->
131 InputAnnotation name tipe ->
128− prettyPort "input" name ":" tipe
132+ prettyWire "input" name ":" tipe
129
133
130 OutputAnnotation name tipe ->
134 OutputAnnotation name tipe ->
131− prettyPort "output" name ":" tipe
135+ prettyWire "output" name ":" tipe
132
136
133− OutputDef name expr ->
137+ OutputDefinition name expr ->
134− prettyPort "output" name "=" expr
138+ prettyWire "output" name "=" expr
135
139
140+ LoopbackAnnotation name tipe ->
141+ prettyWire "loopback" name ":" tipe
136
142
137−instance (Pretty expr, Pretty var, Var.ToString var) => Pretty (Port expr var) where
143+ LoopbackDefinition name expr ->
138− pretty port =
144+ prettyWire "loopback" name "=" expr
139− case port of
140− In name tipe ->
141− prettyPort "input" name ":" tipe
142
145
146+
147+instance (Pretty expr, Pretty var, Var.ToString var) => Pretty (Wire expr var) where
148+ pretty wire =
149+ case wire of
150+ Input name tipe ->
151+ prettyWire "input" name ":" tipe
152+
143− Out name expr tipe ->
153+ Output name expr tipe ->
154+ P.vcat
155+ [ prettyWire "output" name ":" tipe
156+ , prettyWire "output" name "=" expr
157+ ]
158+
159+ Loopback name maybeExpr tipe ->
144 P.vcat
160 P.vcat
145− [ prettyPort "output" name ":" tipe
161+ [ prettyWire "loopback" name ":" tipe
146− , prettyPort "output" name "=" expr
162+ , case maybeExpr of
163+ Just expr ->
164+ prettyWire "loopback" name "=" expr
165+ Nothing ->
166+ P.empty
147 ]
167 ]
148−
149
168
169+
150−prettyPort :: (Pretty a) => String -> String -> String -> a -> Doc
170+prettyWire :: (Pretty a) => String -> String -> String -> a -> Doc
151−prettyPort keyword name op e =
171+prettyWire keyword name op e =
152 P.text keyword <+> P.text name <+> P.text op <+> pretty e
172 P.text keyword <+> P.text name <+> P.text op <+> pretty e
src/AST/Expression/General.hs+11−7
@@ -58,8 +58,9 @@ data Expr' ann def var
58 | Modify (Expr ann def var) [(String, Expr ann def var)]
58 | Modify (Expr ann def var) [(String, Expr ann def var)]
59 | Record [(String, Expr ann def var)]
59 | Record [(String, Expr ann def var)]
60 -- for type checking and code gen only
60 -- for type checking and code gen only
61− | PortIn String (Type var)
61+ | Input String (Type var)
62− | PortOut String (Type var) (Expr ann def var)
62+ | Output String (Type var) (Expr ann def var)
63+ | Loopback String (Type var) (Maybe (Expr ann def var))
63 | GLShader String String Literal.GLShaderTipe
64 | GLShader String String Literal.GLShaderTipe
64 deriving (Show)
65 deriving (Show)
65
66
@@ -87,7 +88,7 @@ saveEnvName =
87
88
88
89
89dummyLet :: (Pretty def) => [def] -> Expr Annotation.Region def Var.Canonical
90dummyLet :: (Pretty def) => [def] -> Expr Annotation.Region def Var.Canonical
90−dummyLet defs =
91+dummyLet defs =
91 Annotation.none $ Let defs (Annotation.none $ Var (Var.builtin saveEnvName))
92 Annotation.none $ Let defs (Annotation.none $ Var (Var.builtin saveEnvName))
92
93
93
94
@@ -194,11 +195,14 @@ instance (Pretty def, Pretty var, Var.ToString var) => Pretty (Expr' ann def var
194 GLShader _ _ _ ->
195 GLShader _ _ _ ->
195 P.text "[glsl| ... |]"
196 P.text "[glsl| ... |]"
196
197
197− PortIn name _ ->
198+ Input name _ ->
198− P.text $ "<port:" ++ name ++ ">"
199+ P.text ("<input:" ++ name ++ ">")
199
200
200− PortOut _ _ signal ->
201+ Output name _ _ ->
201− pretty signal
202+ P.text ("<output:" ++ name ++ ">")
203+
204+ Loopback name _ _ ->
205+ P.text ("<loopback:" ++ name ++ ">")
202
206
203
207
204collectApps :: Expr ann def var -> [Expr ann def var]
208collectApps :: Expr ann def var -> [Expr ann def var]
src/AST/Variable.hs+8−3
@@ -63,9 +63,14 @@ isArray =
63 is ["Array"] "Array"
63 is ["Array"] "Array"
64
64
65
65
66−isSignal :: Canonical -> Bool
66+isStream :: Canonical -> Bool
67−isSignal =
67+isStream =
68− is ["Signal"] "Signal"
68+ is ["Signal"] "Stream"
69+
70+
71+isVarying :: Canonical -> Bool
72+isVarying =
73+ is ["Signal"] "Varying"
69
74
70
75
71isPromise :: Canonical -> Bool
76isPromise :: Canonical -> Bool
src/Docs.hs+1−1
@@ -200,7 +200,7 @@ collectInfo (comment, decl) info =
200 in
200 in
201 info { infixes = Map.insert name infixInfo (infixes info) }
201 info { infixes = Map.insert name infixInfo (infixes info) }
202
202
203− Decl.Port _ ->
203+ Decl.Wire _ ->
204 error errorMessage
204 error errorMessage
205
205
206
206
src/Parse/Declaration.hs+42−34
@@ -12,11 +12,12 @@ import qualified Parse.Type as Type
12
12
13declaration :: IParser D.SourceDecl
13declaration :: IParser D.SourceDecl
14declaration =
14declaration =
15− typeDecl <|> infixDecl <|> input <|> output <|> definition
15+ typeDecl <|> infixDecl <|> loopback <|> input <|> output <|> definition
16
16
17
17
18definition :: IParser D.SourceDecl
18definition :: IParser D.SourceDecl
19+definition =
19−definition = D.Definition <$> Expr.def
20+ D.Definition <$> Expr.def
20
21
21
22
22typeDecl :: IParser D.SourceDecl
23typeDecl :: IParser D.SourceDecl
@@ -40,48 +41,55 @@ typeDecl =
40
41
41
42
42infixDecl :: IParser D.SourceDecl
43infixDecl :: IParser D.SourceDecl
43−infixDecl = do
44+infixDecl =
44− assoc <-
45+ do assoc <-
45− choice
46+ choice
46− [ try (reserved "infixl") >> return D.L
47+ [ try (reserved "infixl") >> return D.L
47− , try (reserved "infixr") >> return D.R
48+ , try (reserved "infixr") >> return D.R
48− , try (reserved "infix") >> return D.N
49+ , try (reserved "infix") >> return D.N
49− ]
50+ ]
50− forcedWS
51+ forcedWS
51− n <- digit
52+ n <- digit
52− forcedWS
53+ forcedWS
53− D.Fixity assoc (read [n]) <$> anyOp
54+ D.Fixity assoc (read [n]) <$> anyOp
54
55
55
56
56input :: IParser D.SourceDecl
57input :: IParser D.SourceDecl
57input =
58input =
58− do try (reserved "input")
59+ do name <- wireBegining "input"
59− whitespace
60− name <- lowVar
61− whitespace
62− ioEnding D.InputAnnotation name hasType Type.expr
60+ wireEnding (D.InputAnnotation name) hasType Type.expr
63
61
64
62
65output :: IParser D.SourceDecl
63output :: IParser D.SourceDecl
66output =
64output =
65+ do name <- wireBegining "output"
66+ choice
67+ [ wireEnding (D.OutputAnnotation name) hasType Type.expr
68+ , wireEnding (D.OutputDefinition name) equals Expr.expr
69+ ]
70+
71+
72+loopback :: IParser D.SourceDecl
73+loopback =
74+ do name <- wireBegining "loopback"
75+ choice
76+ [ wireEnding (D.LoopbackAnnotation name) hasType Type.expr
77+ , wireEnding (D.LoopbackDefinition name) equals Expr.expr
78+ ]
79+
80+
81+wireBegining :: String -> IParser String
82+wireBegining keyword =
67− do try (reserved "output")
83+ do try (reserved keyword)
68 whitespace
84 whitespace
69 name <- lowVar
85 name <- lowVar
70 whitespace
86 whitespace
71− choice
87+ return name
72− [ ioEnding D.OutputAnnotation name hasType Type.expr
73− , ioEnding D.OutputDef name equals Expr.expr
74− ]
75
88
76
89
77−ioEnding
78− :: (String -> a -> D.RawPort)
79− -> String
80− -> IParser String
81− -> IParser a
82− -> IParser D.SourceDecl
90+wireEnding :: (a -> D.RawWire) -> IParser String -> IParser a -> IParser D.SourceDecl
83−ioEnding decl name op valueParser =
91+wireEnding makeWire op valueParser =
84− do op
92+ do op
85− whitespace
93+ whitespace
86− value <- valueParser
94+ value <- valueParser
87− return (D.Port (decl name value))
95+ return (D.Wire (makeWire value))
src/Parse/Helpers.hs+2−2
@@ -31,9 +31,9 @@ reserveds =
31 , "type"
31 , "type"
32 , "module", "where"
32 , "module", "where"
33 , "import", "as", "hiding", "exposing"
33 , "import", "as", "hiding", "exposing"
34− , "export", "foreign"
34+ , "export"
35 , "deriving"
35 , "deriving"
36− , "input", "output"
36+ , "input", "output", "loopback"
37 ]
37 ]
38
38
39
39
src/Transform/Canonicalize.hs+24−15
@@ -76,7 +76,7 @@ moduleHelp interfaces modul@(Module.Module _ _ exports _ decls) =
76 , aliases =
76 , aliases =
77 Map.fromList [ (name,(tvs,alias)) | D.TypeAlias name tvs alias <- decls ]
77 Map.fromList [ (name,(tvs,alias)) | D.TypeAlias name tvs alias <- decls ]
78 , ports =
78 , ports =
79− [ D.portName port | D.Port port <- decls ]
79+ [ D.wireName wire | D.Wire wire <- decls ]
80 }
80 }
81
81
82
82
@@ -181,7 +181,7 @@ declaration env decl =
181 let canonicalize kind context pattern env v =
181 let canonicalize kind context pattern env v =
182 let ctx = P.text ("Error in " ++ context) <+> pretty pattern <> P.colon
182 let ctx = P.text ("Error in " ++ context) <+> pretty pattern <> P.colon
183 throw err = P.vcat [ ctx, P.text err ]
183 throw err = P.vcat [ ctx, P.text err ]
184− in
184+ in
185 Env.onError throw (kind env v)
185 Env.onError throw (kind env v)
186 in
186 in
187 case decl of
187 case decl of
@@ -201,18 +201,24 @@ declaration env decl =
201 do expanded' <- canonicalize Canonicalize.tipe "type alias" name env expanded
201 do expanded' <- canonicalize Canonicalize.tipe "type alias" name env expanded
202 return (D.TypeAlias name tvars expanded')
202 return (D.TypeAlias name tvars expanded')
203
203
204− D.Port port ->
204+ D.Wire wire ->
205 do Env.uses ["Native","Ports"]
205 do Env.uses ["Native","Ports"]
206 Env.uses ["Native","Json"]
206 Env.uses ["Native","Json"]
207− D.Port <$>
207+ D.Wire <$>
208− case port of
208+ case wire of
209− D.In name t ->
209+ D.Input name t ->
210− do t' <- canonicalize Canonicalize.tipe "port" name env t
210+ do t' <- canonicalize Canonicalize.tipe "input" name env t
211− return (D.In name t')
211+ return (D.Input name t')
212+
212− D.Out name e t ->
213+ D.Output name e t ->
213 do e' <- expression env e
214 do e' <- expression env e
214− t' <- canonicalize Canonicalize.tipe "port" name env t
215+ t' <- canonicalize Canonicalize.tipe "output" name env t
215− return (D.Out name e' t')
216+ return (D.Output name e' t')
217+
218+ D.Loopback name maybeExpr t ->
219+ do maybeExpr' <- T.traverse (expression env) maybeExpr
220+ t' <- canonicalize Canonicalize.tipe "input" name env t
221+ return (D.Loopback name maybeExpr' t')
216
222
217 D.Fixity assoc prec op ->
223 D.Fixity assoc prec op ->
218 return $ D.Fixity assoc prec op
224 return $ D.Fixity assoc prec op
@@ -298,11 +304,14 @@ expression env (A.A ann expr) =
298 (,) <$> format (pattern env p)
304 (,) <$> format (pattern env p)
299 <*> expression (Env.addPattern p env) b
305 <*> expression (Env.addPattern p env) b
300
306
307+ Input name tipe ->
308+ Input name <$> tipe' env tipe
309+
301− PortIn name st ->
310+ Output name st signal ->
302− PortIn name <$> tipe' env st
311+ Output name <$> tipe' env st <*> go signal
303
312
304− PortOut name st signal ->
313+ Loopback name st maybeExpr ->
305− PortOut name <$> tipe' env st <*> go signal
314+ Loopback name <$> tipe' env st <*> T.traverse go maybeExpr
306
315
307 GLShader uid src tipe ->
316 GLShader uid src tipe ->
308 return (GLShader uid src tipe)
317 return (GLShader uid src tipe)
src/Transform/Canonicalize/Setup.hs+6−11
@@ -220,7 +220,7 @@ addTypeAlias moduleName env scc =
220 in P.vcat [ P.text msg, P.text err ]
220 in P.vcat [ P.text msg, P.text err ]
221
221
222 aliases ->
222 aliases ->
223− throwError
223+ throwError
224 [ P.vcat
224 [ P.vcat
225 [ P.text (eightyCharLines 0 mutuallyRecursiveMessage)
225 [ P.text (eightyCharLines 0 mutuallyRecursiveMessage)
226 , indented (map typeAlias aliases)
226 , indented (map typeAlias aliases)
@@ -311,15 +311,10 @@ addDecl moduleName info@(nodes,env) decl =
311 _values env
311 _values env
312 }
312 }
313
313
314− D.Port port ->
314+ D.Wire wire ->
315− let portName =
316− case port of
317− D.Out name _ _ -> name
318− D.In name _ -> name
319− in
320− (,) nodes $ env
315+ (,) nodes $ env
321− { _values =
316+ { _values =
322− addLocal portName (_values env)
317+ addLocal (D.wireName wire) (_values env)
323− }
318+ }
324
319
325 D.Fixity _ _ _ -> info
320 D.Fixity _ _ _ -> info
src/Transform/Check.hs+6−5
@@ -52,11 +52,12 @@ duplicateValues decls =
52 unzip [ (pat,expr) | D.Definition (Valid.Definition pat expr _) <- decls ]
52 unzip [ (pat,expr) | D.Definition (Valid.Definition pat expr _) <- decls ]
53
53
54 (portNames, portExprs) =
54 (portNames, portExprs) =
55− Arrow.second concat $ unzip $
55+ Arrow.second Maybe.catMaybes $ unzip $
56− flip map [ port | D.Port port <- decls ] $ \port ->
56+ flip map [ wire | D.Wire wire <- decls ] $ \wire ->
57− case port of
57+ case wire of
58+ D.Input name _ -> (name, Nothing)
58− D.Out name expr _ -> (name, [expr])
59+ D.Output name expr _ -> (name, Just expr)
59− D.In name _ -> (name, [])
60+ D.Loopback name maybeExpr _ -> (name, maybeExpr)
60
61
61 exprDups :: Valid.Expr -> Either String Valid.Expr
62 exprDups :: Valid.Expr -> Either String Valid.Expr
62 exprDups expr = Expr.crawlLet defsDups expr
63 exprDups expr = Expr.crawlLet defsDups expr
src/Transform/Declaration.hs+44−27
@@ -22,15 +22,18 @@ combineAnnotations :: [D.SourceDecl] -> Either String [D.ValidDecl]
22combineAnnotations =
22combineAnnotations =
23 go
23 go
24 where
24 where
25+ errorMessage kind name =
25− msg x = "Syntax Error: The type annotation for '" ++ x ++
26+ "Syntax Error: The type annotation for " ++ kind ++ " '" ++
26− "' must be directly above its definition."
27+ name ++ "' must be directly above its definition."
27
28
29+ exprCombineAnnotations =
28− exprCombineAnnotations = Expr.crawlLet Def.combineAnnotations
30+ Expr.crawlLet Def.combineAnnotations
29
31
30 go decls =
32 go decls =
31 case decls of
33 case decls of
32 -- simple cases, pass them through with no changes
34 -- simple cases, pass them through with no changes
35+ [] ->
33− [] -> return []
36+ return []
34
37
35 D.Datatype name tvars ctors : rest ->
38 D.Datatype name tvars ctors : rest ->
36 (:) (D.Datatype name tvars ctors) <$> go rest
39 (:) (D.Datatype name tvars ctors) <$> go rest
@@ -45,37 +48,49 @@ combineAnnotations =
45 D.Definition def : defRest ->
48 D.Definition def : defRest ->
46 case def of
49 case def of
47 Source.Definition pat expr ->
50 Source.Definition pat expr ->
48− do expr' <- exprCombineAnnotations expr
51+ do expr' <- exprCombineAnnotations expr
49− let def' = Valid.Definition pat expr' Nothing
52+ let def' = Valid.Definition pat expr' Nothing
50− (:) (D.Definition def') <$> go defRest
53+ (:) (D.Definition def') <$> go defRest
51
54
52 Source.TypeAnnotation name tipe ->
55 Source.TypeAnnotation name tipe ->
53 case defRest of
56 case defRest of
54 D.Definition (Source.Definition pat@(P.Var name') expr) : rest
57 D.Definition (Source.Definition pat@(P.Var name') expr) : rest
55 | name == name' ->
58 | name == name' ->
56− do expr' <- exprCombineAnnotations expr
59+ do expr' <- exprCombineAnnotations expr
57− let def' = Valid.Definition pat expr' (Just tipe)
60+ let def' = Valid.Definition pat expr' (Just tipe)
58− (:) (D.Definition def') <$> go rest
61+ (:) (D.Definition def') <$> go rest
59
62
60− _ -> Left (msg name)
63+ _ -> Left (errorMessage "value" name)
61
64
62− -- combine ports
65+ -- combine wires
63− D.Port port : portRest ->
66+ D.Wire wire : wireRest ->
64− case port of
67+ case wire of
65 D.InputAnnotation name tipe ->
68 D.InputAnnotation name tipe ->
66− (:) (D.Port (D.In name tipe)) <$> go portRest
69+ (:) (D.Wire (D.Input name tipe)) <$> go wireRest
67
70
68− D.OutputDef name _ ->
71+ D.OutputDefinition name _ ->
69− Left (msg name)
72+ Left (errorMessage "output" name)
70
73
71 D.OutputAnnotation name tipe ->
74 D.OutputAnnotation name tipe ->
72− case portRest of
75+ case wireRest of
73− D.Port (D.OutputDef name' expr) : rest | name == name' ->
76+ D.Wire (D.OutputDefinition name' expr) : rest | name == name' ->
74 do expr' <- exprCombineAnnotations expr
77 do expr' <- exprCombineAnnotations expr
75− (:) (D.Port (D.Out name expr' tipe)) <$> go rest
78+ (:) (D.Wire (D.Output name expr' tipe)) <$> go rest
76
79
77 _ ->
80 _ ->
78− Left (msg name)
81+ Left (errorMessage "output" name)
82+
83+ D.LoopbackDefinition name tipe ->
84+ Left (errorMessage "loopback" name)
85+
86+ D.LoopbackAnnotation name tipe ->
87+ case wireRest of
88+ D.Wire (D.LoopbackDefinition name' expr) : rest | name == name' ->
89+ do expr' <- exprCombineAnnotations expr
90+ (:) (D.Wire (D.Loopback name (Just expr') tipe)) <$> go rest
91+
92+ _ ->
93+ (:) (D.Wire (D.Loopback name Nothing tipe)) <$> go wireRest
79
94
80
95
81toExpr :: Module.Name -> [D.CanonicalDecl] -> [Canonical.Def]
96toExpr :: Module.Name -> [D.CanonicalDecl] -> [Canonical.Def]
@@ -122,12 +137,14 @@ toDefs moduleName decl =
122 D.TypeAlias _ _ _ ->
137 D.TypeAlias _ _ _ ->
123 []
138 []
124
139
125− D.Port port ->
140+ D.Wire wire ->
126− case port of
141+ case wire of
127− D.Out name expr@(A.A s _) tipe ->
142+ D.Output name expr@(A.A s _) tipe ->
128− [ definition name (A.A s $ E.PortOut name tipe expr) tipe ]
143+ [ definition name (A.A s $ E.Output name tipe expr) tipe ]
144+ D.Input name tipe ->
145+ [ definition name (A.none $ E.Input name tipe) tipe ]
129− D.In name tipe ->
146+ D.Loopback name maybeExpr tipe ->
130− [ definition name (A.none $ E.PortIn name tipe) tipe ]
147+ [ definition name (A.none $ E.Loopback name tipe maybeExpr) tipe ]
131
148
132 -- no constraints are needed for fixity declarations
149 -- no constraints are needed for fixity declarations
133 D.Fixity _ _ _ ->
150 D.Fixity _ _ _ ->
src/Transform/SortDefinitions.hs+8−4
@@ -111,11 +111,15 @@ reorder (A ann expr) =
111 GLShader _ _ _ ->
111 GLShader _ _ _ ->
112 return expr
112 return expr
113
113
114− PortOut name st signal ->
114+ Input name st ->
115− PortOut name st <$> reorder signal
115+ return $ Input name st
116
116
117− PortIn name st ->
117+ Output name st signal ->
118− return $ PortIn name st
118+ Output name st <$> reorder signal
119+
120+ Loopback name st maybeExpr ->
121+ Loopback name st <$>
122+ maybe (return Nothing) (fmap Just . reorder) maybeExpr
119
123
120 -- Actually do some reordering
124 -- Actually do some reordering
121 Let defs body ->
125 Let defs body ->
src/Transform/Substitute.hs+7−4
@@ -81,8 +81,11 @@ subst old new expression =
81
81
82 GLShader _ _ _ -> expression
82 GLShader _ _ _ -> expression
83
83
84− PortIn name st ->
84+ Input name st ->
85− PortIn name st
85+ Input name st
86
86
87− PortOut name st signal ->
87+ Output name st expr ->
88− PortOut name st (f signal)
88+ Output name st (f expr)
89+
90+ Loopback name tipe maybeExpr ->
91+ Loopback name tipe (fmap f maybeExpr)
src/Type/Constrain/Expression.hs+10−2
@@ -165,11 +165,19 @@ constrain env (A region expr) tipe =
165 (clet [Scheme rqs fqs (clet [monoscheme header] c2) header ]
165 (clet [Scheme rqs fqs (clet [monoscheme header] c2) header ]
166 (c1 /\ c))
166 (c1 /\ c))
167
167
168+ Input _ _ ->
168− PortIn _ _ -> return true
169+ return true
169
170
170− PortOut _ _ signal ->
171+ Output _ _ signal ->
171 constrain env signal tipe
172 constrain env signal tipe
172
173
174+ Loopback _ _ maybeExpr ->
175+ case maybeExpr of
176+ Nothing ->
177+ return true
178+ Just expr ->
179+ constrain env expr tipe
180+
173
181
174constrainDef env info (Canonical.Definition pattern expr maybeTipe) =
182constrainDef env info (Canonical.Definition pattern expr maybeTipe) =
175 let qs = [] -- should come from the def, but I'm not sure what would live there...
183 let qs = [] -- should come from the def, but I'm not sure what would live there...