on master help sign in
Update input/output generation for new Ports implementation
6549a4eEvan Czaplicki
src/Generate/JavaScript/Foreign.hs+23−10
@@ -2,6 +2,7 @@ module Generate.JavaScript.Foreign (input, output) where
2
2
3import qualified Data.List as List
3import qualified Data.List as List
4import Generate.JavaScript.Helpers
4import Generate.JavaScript.Helpers
5+import AST.PrettyPrint (pretty)
5import AST.Type as T
6import AST.Type as T
6import qualified AST.Variable as Var
7import qualified AST.Variable as Var
7import Language.ECMAScript3.Syntax
8import Language.ECMAScript3.Syntax
@@ -65,16 +66,22 @@ check x jsType continue =
65
66
66input :: String -> CanonicalType -> Expression ()
67input :: String -> CanonicalType -> Expression ()
67input name tipe =
68input name tipe =
69+ let args t =
70+ [ string name, string (show (pretty t)), toTypeFunction t ]
71+ in
68− case T.dealias tipe of
72+ case tipe of
73+ Aliased _ t ->
74+ input name t
75+
69 App (Type signal) [t]
76 App (Type signal) [t]
70 | Var.isStream signal ->
77 | Var.isStream signal ->
71− obj ["_P","inputStream"] <| toTypeFunction t
78+ obj ["_P","inputStream"] `call` args t
72
79
73 | Var.isVarying signal ->
80 | Var.isVarying signal ->
74− obj ["_P","inputVarying"] <| toTypeFunction t
81+ obj ["_P","inputVarying"] `call` args t
75
82
76− dealiasedType ->
83+ _ ->
77− obj ["_P","inputValue"] <| toTypeFunction dealiasedType
84+ obj ["_P","inputValue"] `call` args tipe
78
85
79
86
80toTypeFunction :: CanonicalType -> Expression ()
87toTypeFunction :: CanonicalType -> Expression ()
@@ -166,16 +173,22 @@ toTuple types x =
166
173
167output :: String -> CanonicalType -> Expression () -> Expression ()
174output :: String -> CanonicalType -> Expression () -> Expression ()
168output name tipe value =
175output name tipe value =
176+ let args t =
177+ [ string name, fromTypeFunction t, value ]
178+ in
169− case T.dealias tipe of
179+ case tipe of
180+ Aliased _ t ->
181+ output name t value
182+
170 App (Type signal) [t]
183 App (Type signal) [t]
171 | Var.isStream signal ->
184 | Var.isStream signal ->
172− obj ["_P","outputStream"] `call` [ fromTypeFunction t, value ]
185+ obj ["_P","outputStream"] `call` args t
173
186
174 | Var.isVarying signal ->
187 | Var.isVarying signal ->
175− obj ["_P","outputVarying"] `call` [ fromTypeFunction t, value ]
188+ obj ["_P","outputVarying"] `call` args t
176
189
177− dealiasedType ->
190+ _ ->
178− obj ["_P","outputValue"] `call` [ fromTypeFunction dealiasedType, value ]
191+ obj ["_P","outputValue"] `call` args tipe
179
192
180
193
181fromTypeFunction :: CanonicalType -> Expression ()
194fromTypeFunction :: CanonicalType -> Expression ()