on master help sign in
Minor style improvements, switch to using helper function
458bf2bEvan Czaplicki
compiler/Generate/JavaScript/Ports.hs+22−16
@@ -32,7 +32,7 @@ incoming tipe =
32
32
33inc :: Type -> Expression () -> Expression ()
33inc :: Type -> Expression () -> Expression ()
34inc tipe x =
34inc 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 Data ctor []
38 Data ctor []
@@ -58,22 +58,26 @@ inc tipe x =
58 where
58 where
59 array = DotRef () x (var "map") <| incoming t
59 array = DotRef () x (var "map") <| incoming t
60
60
61+ Data ctor ts
61− Data ctor ts | Help.isTuple ctor -> check x JSArray tuple
62+ | Help.isTuple ctor -> check x JSArray tuple
62 where
63 where
63− tuple = ObjectLit () $ (PropId () (var "ctor"), string ctor) : values
64+ tuple = ObjectLit () $ (prop "ctor", string ctor) : values
64 values = zipWith convert [0..] ts
65 values = zipWith convert [0..] ts
65− convert n t = ( PropId () $ var ('_':show n)
66+ convert n t = ( prop ('_':show n)
66 , inc t (BracketRef () x (IntLit () n)))
67 , inc t (BracketRef () x (IntLit () n)))
67
68
69+ Data _ _ ->
68− Data _ _ -> error "bad ADT got to port generation code"
70+ error "bad ADT got to port generation code"
69
71
72+ Record _ (Just _) ->
70− Record _ (Just _) -> error "bad record got to port generation code"
73+ error "bad record got to port generation code"
71
74
75+ Record fields Nothing ->
72− Record fields Nothing -> check x (JSObject (map fst fields)) object
76+ check x (JSObject (map fst fields)) object
73 where
77 where
74− object = ObjectLit () $ (PropId () (var "_"), ObjectLit () []) : keys
78+ object = ObjectLit () $ (prop "_", ObjectLit () []) : keys
75 keys = map convert fields
79 keys = map convert fields
76− convert (f,t) = (PropId () (var f), inc t (DotRef () x (var f)))
80+ convert (f,t) = (prop f, inc t (DotRef () x (var f)))
77
81
78outgoing tipe =
82outgoing tipe =
79 case tipe of
83 case tipe of
@@ -114,14 +118,16 @@ out tipe x =
114 | ctor == "_List" ->
118 | ctor == "_List" ->
115 DotRef () (obj "_J.fromList" <| x) (var "map") <| outgoing t
119 DotRef () (obj "_J.fromList" <| x) (var "map") <| outgoing t
116
120
121+ Data ctor ts
117− Data ctor ts | Help.isTuple ctor ->
122+ | Help.isTuple ctor ->
118− ArrayLit () $ zipWith convert [0..] ts
119− where
120− convert n t = out t $ DotRef () x $ var ('_':show n)
123+ let convert n t = out t $ DotRef () x $ var ('_':show n)
121−
124+ in ArrayLit () $ zipWith convert [0..] ts
125+
126+ Data _ _ ->
122− Data _ _ -> error "bad ADT got to port generation code"
127+ error "bad ADT got to port generation code"
123
128
129+ Record _ (Just _) ->
124− Record _ (Just _) -> error "bad record got to port generation code"
130+ error "bad record got to port generation code"
125
131
126 Record fields Nothing ->
132 Record fields Nothing ->
127 ObjectLit () keys
133 ObjectLit () keys