on master help sign in
Allow Arrays to pass through ports

Closes elm-lang/Elm#597

commitf99ac9741d2ae5f255e02907c46749e4158a5e10 authorMax Goldstein <maxgoldstein1@gmail.com> dateTue 29 Apr 2014, 23:58 (13 years ago) parent408a8c8
3 files changed+12−5
compiler/Generate/JavaScript.hs+1 compiler/Generate/JavaScript/Ports.hs+9−2 compiler/Type/ExtraChecks.hs+2−3
compiler/Generate/JavaScript.hs+1
@@ -38,6 +38,7 @@ internalImports name =
3838 [ varDecl "_N" (obj "Elm.Native")
3939 , include "_U" "_N.Utils"
4040 , include "_L" "_N.List"
41+ , include "_A" "_N.Array"
4142 , include "_E" "_N.Error"
4243 , varDecl "$moduleName" (string name)
4344 ]
compiler/Generate/JavaScript/Ports.hs+9−2
@@ -55,8 +55,12 @@ inc tipe x =
5555
5656 | ctor == "_List" ->
5757 check x JSArray (obj "_L.fromArray" <| array)
58− where
59− array = DotRef () x (var "map") <| incoming t
58+
59+ | ctor == "Array.Array" ->
60+ check x JSArray (obj "_A.fromJSArray" <| array)
61+
62+ where
63+ array = DotRef () x (var "map") <| incoming t
6064
6165 Data ctor ts
6266 | Help.isTuple ctor -> check x JSArray tuple
@@ -117,6 +121,9 @@ out tipe x =
117121 | ctor == "_List" ->
118122 DotRef () (obj "_L.toArray" <| x) (var "map") <| outgoing t
119123
124+ | ctor == "Array.Array" ->
125+ DotRef () (obj "_A.toJSArray" <| x) (var "map") <| outgoing t
126+
120127 Data ctor ts
121128 | Help.isTuple ctor ->
122129 let convert n t = out t $ DotRef () x $ var ('_':show n)
compiler/Type/ExtraChecks.hs+2−3
@@ -60,8 +60,7 @@ portTypes rules expr =
6060 | otherwise -> err' True "an unsupported type"
6161 where
6262 primitives =
63− ["Int","Float","String","Bool","Maybe.Maybe","_List","Json.Value"]
64−
63+ ["Int","Float","String","Bool","Maybe.Maybe","_List","Array.Array","Json.Value"]
6564 validConstructor =
6665 ctor `elem` primitives || Help.isTuple ctor
6766
@@ -102,7 +101,7 @@ portTypes rules expr =
102101 , txt [ "It contains ", kind, ":\n" ]
103102 , (P.nest 4 . SPP.pretty $ Alias.realias rules tipe) <> P.text "\n"
104103 , txt [ "Acceptable values for ", dir "incoming" "outgoing", " ports include:" ]
105− , txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Tuples," ]
104+ , txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples," ]
106105 , txt [ " Json.Values, ", dir "" "first-order functions, ", "and concrete records." ]
107106 ] ++ if couldBeAlias then aliasWarning else []
108107