on master help sign in
Allow raw JavaScript values through ports (experiment)
cc9c97bEvan Czaplicki
compiler/AST/Variable.hs+3
@@ -32,6 +32,9 @@ is :: [String] -> String -> Canonical -> Bool
32is home name var =
32is home name var =
33 var == Canonical (Module home) name
33 var == Canonical (Module home) name
34
34
35+isJavaScript :: Canonical -> Bool
36+isJavaScript = is ["JavaScript"] "Value"
37+
35isJson :: Canonical -> Bool
38isJson :: Canonical -> Bool
36isJson = is ["Json"] "Value"
39isJson = is ["Json"] "Value"
37
40
compiler/Generate/JavaScript/Ports.hs+11−3
@@ -73,9 +73,17 @@ inc tipe x =
73 from checks = check x checks x
73 from checks = check x checks x
74
74
75 Type name
75 Type name
76+ | Var.isJavaScript name ->
77+ x
78+
79+ | Var.isJson name ->
76− | Var.isJson name -> V.value ["Native","Json"] "fromJS" <| x
80+ V.value ["Native","Json"] "fromJS" <| x
81+
77− | Var.isTuple name -> incomingTuple [] x
82+ | Var.isTuple name ->
83+ incomingTuple [] x
84+
85+ | otherwise ->
78− | otherwise -> error "bad type got to incoming port generation code"
86+ error "bad type got to incoming port generation code"
79
87
80 App f args ->
88 App f args ->
81 case f : args of
89 case f : args of
compiler/Type/ExtraChecks.hs+4−5
@@ -62,11 +62,10 @@ portTypes expr =
62 case tipe of
62 case tipe of
63 ST.Aliased _ t -> valid t
63 ST.Aliased _ t -> valid t
64
64
65− ST.Type v
65+ ST.Type v ->
66− | V.isJson v -> return ()
66+ case any ($ v) [ V.isJson, V.isPrimitive, V.isTuple, V.isJavaScript ] of
67− | V.isPrimitive v -> return ()
68− | V.isTuple v -> return ()
67+ True -> return ()
69− | otherwise -> err "an unsupported type"
68+ False -> err "an unsupported type"
70
69
71 ST.App t [] -> valid t
70 ST.App t [] -> valid t
72
71