Skip to content

Commit

Permalink
Allow Arrays to pass through ports
Browse files Browse the repository at this point in the history
Closes elm#597
  • Loading branch information
mgold committed May 1, 2014
1 parent 408a8c8 commit f99ac97
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions compiler/Generate/JavaScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internalImports name =
[ varDecl "_N" (obj "Elm.Native")
, include "_U" "_N.Utils"
, include "_L" "_N.List"
, include "_A" "_N.Array"
, include "_E" "_N.Error"
, varDecl "$moduleName" (string name)
]
Expand Down
11 changes: 9 additions & 2 deletions compiler/Generate/JavaScript/Ports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ inc tipe x =

| ctor == "_List" ->
check x JSArray (obj "_L.fromArray" <| array)
where
array = DotRef () x (var "map") <| incoming t

| ctor == "Array.Array" ->
check x JSArray (obj "_A.fromJSArray" <| array)

where
array = DotRef () x (var "map") <| incoming t

Data ctor ts
| Help.isTuple ctor -> check x JSArray tuple
Expand Down Expand Up @@ -117,6 +121,9 @@ out tipe x =
| ctor == "_List" ->
DotRef () (obj "_L.toArray" <| x) (var "map") <| outgoing t

| ctor == "Array.Array" ->
DotRef () (obj "_A.toJSArray" <| x) (var "map") <| outgoing t

Data ctor ts
| Help.isTuple ctor ->
let convert n t = out t $ DotRef () x $ var ('_':show n)
Expand Down
5 changes: 2 additions & 3 deletions compiler/Type/ExtraChecks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ portTypes rules expr =
| otherwise -> err' True "an unsupported type"
where
primitives =
["Int","Float","String","Bool","Maybe.Maybe","_List","Json.Value"]

["Int","Float","String","Bool","Maybe.Maybe","_List","Array.Array","Json.Value"]
validConstructor =
ctor `elem` primitives || Help.isTuple ctor

Expand Down Expand Up @@ -102,7 +101,7 @@ portTypes rules expr =
, txt [ "It contains ", kind, ":\n" ]
, (P.nest 4 . SPP.pretty $ Alias.realias rules tipe) <> P.text "\n"
, txt [ "Acceptable values for ", dir "incoming" "outgoing", " ports include:" ]
, txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Tuples," ]
, txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples," ]
, txt [ " Json.Values, ", dir "" "first-order functions, ", "and concrete records." ]
] ++ if couldBeAlias then aliasWarning else []

Expand Down

0 comments on commit f99ac97

Please sign in to comment.