diff options
author | 2009-01-01 16:11:42 -0500 | |
---|---|---|
committer | 2009-01-01 16:11:42 -0500 | |
commit | 36e59f6512af87c02ba856372d71a6a47e9045fd (patch) | |
tree | 80d53bab75fbe437b17753868f154b870721d15b | |
parent | 17ffca0b16e45aa093a9c1d55b0e629a4cf26798 (diff) |
Injecting strings and bools
-rw-r--r-- | src/jscomp.sml | 16 | ||||
-rw-r--r-- | tests/jsinj.ur | 16 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/jscomp.sml b/src/jscomp.sml index ca6508a9..d7017a47 100644 --- a/src/jscomp.sml +++ b/src/jscomp.sml @@ -162,10 +162,24 @@ fun process file = (EFfiApp ("Basis", "htmlifyInt", [e]), loc)] | TRecord [] => str loc "null" - | TFfi ("Basis", "string") => e + | TFfi ("Basis", "string") => (EFfiApp ("Basis", "jsifyString", [e]), loc) | TFfi ("Basis", "int") => (EFfiApp ("Basis", "htmlifyInt", [e]), loc) | TFfi ("Basis", "float") => (EFfiApp ("Basis", "htmlifyFloat", [e]), loc) + | TFfi ("Basis", "bool") => (ECase (e, + [((PCon (Enum, PConFfi {mod = "Basis", + datatyp = "bool", + con = "True", + arg = NONE}, NONE), loc), + str loc "true"), + ((PCon (Enum, PConFfi {mod = "Basis", + datatyp = "bool", + con = "False", + arg = NONE}, NONE), loc), + str loc "false")], + {disc = (TFfi ("Basis", "bool"), loc), + result = (TFfi ("Basis", "string"), loc)}), loc) + | _ => (EM.errorAt loc "Don't know how to embed type in JavaScript"; Print.prefaces "Can't embed" [("t", MonoPrint.p_typ MonoEnv.empty t)]; str loc "ERROR") diff --git a/tests/jsinj.ur b/tests/jsinj.ur index d5bd7dbb..bd416720 100644 --- a/tests/jsinj.ur +++ b/tests/jsinj.ur @@ -5,6 +5,8 @@ fun getOpt (t ::: Type) (o : option t) (v : t) : t = cookie int : int cookie float : float +cookie string : string +cookie bool : bool fun main () : transaction page = n <- getCookie int; @@ -15,10 +17,24 @@ fun main () : transaction page = f <- return (getOpt f 1.23); sf <- source 4.56; + s <- getCookie string; + s <- return (getOpt s "Hi"); + ss <- source "Bye"; + + b <- getCookie bool; + b <- return (getOpt b True); + sb <- source False; + return <xml><body> <dyn signal={n <- signal sn; return <xml>{[n]}</xml>}/> <a onclick={set sn n}>CHANGE</a><br/> <dyn signal={f <- signal sf; return <xml>{[f]}</xml>}/> <a onclick={set sf f}>CHANGE</a><br/> + + <dyn signal={s <- signal ss; return <xml>{[s]}</xml>}/> + <a onclick={set ss s}>CHANGE</a><br/> + + <dyn signal={b <- signal sb; return <xml>{[b]}</xml>}/> + <a onclick={set sb b}>CHANGE</a><br/> </body></xml> |