Skip to content

Commit

Permalink
Allow Json.Value through ports
Browse files Browse the repository at this point in the history
  • Loading branch information
process-bot committed Mar 28, 2014
1 parent dfd14a1 commit 32b7c18
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 7 additions & 2 deletions compiler/Generate/JavaScript/Ports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ inc tipe x =
case tipe of
Lambda _ _ -> error "functions should not be allowed through input ports"
Var _ -> error "type variables should not be allowed through input ports"

Data "Json.Value" [] ->
obj "Native.Json.fromJS" <| x

Data ctor []
| ctor == "Int" -> from JSNumber
| ctor == "Float" -> from JSNumber
Expand Down Expand Up @@ -100,8 +104,9 @@ out tipe x =

Var _ -> error "type variables should not be allowed through input ports"
Data ctor []
| ctor `elem` ["Int","Float","Bool","String"] ->
x
| ctor `elem` ["Int","Float","Bool","String"] -> x
| ctor == "Json.Value" ->
obj "Native.Json.toJS" <| x

Data ctor [t]
| ctor == "Maybe.Maybe" ->
Expand Down
4 changes: 3 additions & 1 deletion compiler/Metadata/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ prelude = string ++ text ++ map (\n -> (n, Hiding [])) modules
text = map ((,) "Text") [ As "Text", Hiding ["link", "color", "height"] ]
string = map ((,) "String") [ As "String", Importing ["show"] ]
modules = [ "Basics", "Signal", "List", "Maybe", "Time", "Color"
, "Graphics.Element", "Graphics.Collage", "Native.Ports" ]
, "Graphics.Element", "Graphics.Collage"
, "Native.Ports", "Native.Json"
]

interfaces :: Bool -> IO Interfaces
interfaces noPrelude =
Expand Down
6 changes: 4 additions & 2 deletions compiler/Type/ExtraChecks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ portTypes rules expr =
| ctor == "Signal.Signal" -> handleSignal ts
| otherwise -> err' True "an unsupported type"
where
primitives =
["Int","Float","String","Bool","Maybe.Maybe","_List","Json.Value"]

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

ST.Var _ -> err "free type variables"

Expand Down

0 comments on commit 32b7c18

Please sign in to comment.