on master help sign in
Update input/output generation for new Ports implementation
commit6549a4ec6dc2e140e7767b935937725f6db4c946 authorEvan Czaplicki <info@elm-lang.org> dateSat 28 Feb 2015, 13:56 (12 years ago) parentaf8047c
1 file changed+23−10
src/Generate/JavaScript/Foreign.hs+23−10
src/Generate/JavaScript/Foreign.hs+23−10
@@ -2,6 +2,7 @@ module Generate.JavaScript.Foreign (input, output) where
22
33import qualified Data.List as List
44import Generate.JavaScript.Helpers
5+import AST.PrettyPrint (pretty)
56import AST.Type as T
67import qualified AST.Variable as Var
78import Language.ECMAScript3.Syntax
@@ -65,16 +66,22 @@ check x jsType continue =
6566
6667input :: String -> CanonicalType -> Expression ()
6768input name tipe =
68− case T.dealias tipe of
69+ let args t =
70+ [ string name, string (show (pretty t)), toTypeFunction t ]
71+ in
72+ case tipe of
73+ Aliased _ t ->
74+ input name t
75+
6976 App (Type signal) [t]
7077 | Var.isStream signal ->
71− obj ["_P","inputStream"] <| toTypeFunction t
78+ obj ["_P","inputStream"] `call` args t
7279
7380 | Var.isVarying signal ->
74− obj ["_P","inputVarying"] <| toTypeFunction t
81+ obj ["_P","inputVarying"] `call` args t
7582
76− dealiasedType ->
77− obj ["_P","inputValue"] <| toTypeFunction dealiasedType
83+ _ ->
84+ obj ["_P","inputValue"] `call` args tipe
7885
7986
8087toTypeFunction :: CanonicalType -> Expression ()
@@ -166,16 +173,22 @@ toTuple types x =
166173
167174output :: String -> CanonicalType -> Expression () -> Expression ()
168175output name tipe value =
169− case T.dealias tipe of
176+ let args t =
177+ [ string name, fromTypeFunction t, value ]
178+ in
179+ case tipe of
180+ Aliased _ t ->
181+ output name t value
182+
170183 App (Type signal) [t]
171184 | Var.isStream signal ->
172− obj ["_P","outputStream"] `call` [ fromTypeFunction t, value ]
185+ obj ["_P","outputStream"] `call` args t
173186
174187 | Var.isVarying signal ->
175− obj ["_P","outputVarying"] `call` [ fromTypeFunction t, value ]
188+ obj ["_P","outputVarying"] `call` args t
176189
177− dealiasedType ->
178− obj ["_P","outputValue"] `call` [ fromTypeFunction dealiasedType, value ]
190+ _ ->
191+ obj ["_P","outputValue"] `call` args tipe
179192
180193
181194fromTypeFunction :: CanonicalType -> Expression ()