changeset 592:a8be5a2068a5

Injecting strings and bools
author Adam Chlipala <adamc@hcoop.net>
date Thu, 01 Jan 2009 16:11:42 -0500
parents 8f8771f32909
children f277f5faebcd
files src/jscomp.sml tests/jsinj.ur
diffstat 2 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jscomp.sml	Thu Jan 01 15:59:02 2009 -0500
+++ b/src/jscomp.sml	Thu Jan 01 16:11:42 2009 -0500
@@ -162,10 +162,24 @@
                                    (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")
--- a/tests/jsinj.ur	Thu Jan 01 15:59:02 2009 -0500
+++ b/tests/jsinj.ur	Thu Jan 01 16:11:42 2009 -0500
@@ -5,6 +5,8 @@
 
 cookie int : int
 cookie float : float
+cookie string : string
+cookie bool : bool
 
 fun main () : transaction page =
     n <- getCookie int;
@@ -15,10 +17,24 @@
     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>