on master help sign in
Allow Json.Value through ports
32b7c18Evan Czaplicki
compiler/Generate/JavaScript/Ports.hs+7−2
@@ -35,6 +35,10 @@ inc tipe x =
35 case tipe of
35 case tipe of
36 Lambda _ _ -> error "functions should not be allowed through input ports"
36 Lambda _ _ -> error "functions should not be allowed through input ports"
37 Var _ -> error "type variables should not be allowed through input ports"
37 Var _ -> error "type variables should not be allowed through input ports"
38+
39+ Data "Json.Value" [] ->
40+ obj "Native.Json.fromJS" <| x
41+
38 Data ctor []
42 Data ctor []
39 | ctor == "Int" -> from JSNumber
43 | ctor == "Int" -> from JSNumber
40 | ctor == "Float" -> from JSNumber
44 | ctor == "Float" -> from JSNumber
@@ -100,8 +104,9 @@ out tipe x =
100
104
101 Var _ -> error "type variables should not be allowed through input ports"
105 Var _ -> error "type variables should not be allowed through input ports"
102 Data ctor []
106 Data ctor []
103− | ctor `elem` ["Int","Float","Bool","String"] ->
107+ | ctor `elem` ["Int","Float","Bool","String"] -> x
104− x
108+ | ctor == "Json.Value" ->
109+ obj "Native.Json.toJS" <| x
105
110
106 Data ctor [t]
111 Data ctor [t]
107 | ctor == "Maybe.Maybe" ->
112 | ctor == "Maybe.Maybe" ->
compiler/Metadata/Prelude.hs+3−1
@@ -25,7 +25,9 @@ prelude = string ++ text ++ map (\n -> (n, Hiding [])) modules
25 text = map ((,) "Text") [ As "Text", Hiding ["link", "color", "height"] ]
25 text = map ((,) "Text") [ As "Text", Hiding ["link", "color", "height"] ]
26 string = map ((,) "String") [ As "String", Importing ["show"] ]
26 string = map ((,) "String") [ As "String", Importing ["show"] ]
27 modules = [ "Basics", "Signal", "List", "Maybe", "Time", "Color"
27 modules = [ "Basics", "Signal", "List", "Maybe", "Time", "Color"
28− , "Graphics.Element", "Graphics.Collage", "Native.Ports" ]
28+ , "Graphics.Element", "Graphics.Collage"
29+ , "Native.Ports", "Native.Json"
30+ ]
29
31
30interfaces :: Bool -> IO Interfaces
32interfaces :: Bool -> IO Interfaces
31interfaces noPrelude =
33interfaces noPrelude =
compiler/Type/ExtraChecks.hs+4−2
@@ -59,9 +59,11 @@ portTypes rules expr =
59 | ctor == "Signal.Signal" -> handleSignal ts
59 | ctor == "Signal.Signal" -> handleSignal ts
60 | otherwise -> err' True "an unsupported type"
60 | otherwise -> err' True "an unsupported type"
61 where
61 where
62+ primitives =
63+ ["Int","Float","String","Bool","Maybe.Maybe","_List","Json.Value"]
64+
62 validConstructor =
65 validConstructor =
63− ctor `elem` ["Int","Float","String","Bool","Maybe.Maybe","_List"]
64− || Help.isTuple ctor
66+ ctor `elem` primitives || Help.isTuple ctor
65
67
66 ST.Var _ -> err "free type variables"
68 ST.Var _ -> err "free type variables"
67
69