@@ -2,10 +2,10 @@
2module Generate.JavaScript.Ports (incoming, outgoing) where
2module Generate.JavaScript.Ports (incoming, outgoing) where
4import Generate.JavaScript.Helpers
4import Generate.JavaScript.Helpers
5+import Generate.JavaScript.Variable (nativePorts, nativeJson)
5import AST.Type as T
6import AST.Type as T
6import qualified AST.Variable as Var
7import qualified AST.Variable as Var
7import Language.ECMAScript3.Syntax
8import Language.ECMAScript3.Syntax
8−import Generate.JavaScript.Variable (canonical)
10data JSType = JSNumber | JSBoolean | JSString | JSArray | JSObject [String]
10data JSType = JSNumber | JSBoolean | JSString | JSArray | JSObject [String]
11 deriving Show
11 deriving Show
@@ -30,7 +30,7 @@ incoming tipe =
30 Aliased _ t -> incoming t
30 Aliased _ t -> incoming t
32 App (Type v) [t]
32 App (Type v) [t]
33− | Var.isSignal v -> obj ["_P","incomingSignal"] <| incoming t
33+ | Var.isSignal v -> nativePorts "incomingSignal" <| incoming t
35 _ -> ["v"] ==> inc tipe (ref "v")
35 _ -> ["v"] ==> inc tipe (ref "v")
@@ -51,11 +51,8 @@ inc tipe x =
51 from checks = check x checks x
51 from checks = check x checks x
54− | Var.isJson name -> canonical fromJS <| x
54+ | Var.isJson name -> nativeJson "fromJS" <| x
55 | otherwise -> error "bad type got to incoming port generation code"
55 | otherwise -> error "bad type got to incoming port generation code"
57− fromJS = Var.Canonical (Var.Module "Native.Json") "fromJS"
60 App f args ->
57 App f args ->
61 case f : args of
58 case f : args of
@@ -100,7 +97,7 @@ outgoing tipe =
100 Aliased _ t -> outgoing t
97 Aliased _ t -> outgoing t
102 App (Type v) [t]
99 App (Type v) [t]
103− | Var.isSignal v -> obj ["_P","outgoingSignal"] <| outgoing t
100+ | Var.isSignal v -> nativePorts "outgoingSignal" <| outgoing t
105 _ -> ["v"] ==> out tipe (ref "v")
102 _ -> ["v"] ==> out tipe (ref "v")
@@ -129,10 +126,8 @@ out tipe x =
129 | name `elem` ["Int","Float","Bool","String"] -> x
126 | name `elem` ["Int","Float","Bool","String"] -> x
131 Type name
128 Type name
132− | Var.isJson name -> canonical toJS <| x
129+ | Var.isJson name -> nativeJson "toJS" <| x
133 | otherwise -> error "bad type got to outgoing port generation code"
130 | otherwise -> error "bad type got to outgoing port generation code"
135− toJS = Var.Canonical (Var.Module "Native.Json") "toJS"
137 App f args ->
132 App f args ->
138 case f : args of
133 case f : args of