diff src/mono_opt.sml @ 120:6230bdd122e7

Passing an argument to a web function
author Adam Chlipala <adamc@hcoop.net>
date Sun, 13 Jul 2008 20:07:10 -0400
parents bed5cf0b6b75
children b1cfe49ce692
line wrap: on
line diff
--- a/src/mono_opt.sml	Sun Jul 13 16:11:25 2008 -0400
+++ b/src/mono_opt.sml	Sun Jul 13 20:07:10 2008 -0400
@@ -51,6 +51,25 @@
                                                else
                                                    "&#" ^ Int.toString (ord ch) ^ ";")
 
+val urlifyInt = attrifyInt
+val urlifyFloat = attrifyFloat
+
+fun hexIt ch =
+    let
+        val s = Int.fmt StringCvt.HEX (ord ch)
+    in
+        case size s of
+            0 => "00"
+          | 1 => "0" ^ s
+          | _ => s
+    end
+
+val urlifyString = String.translate (fn #" " => "+"
+                                      | ch => if Char.isAlphaNum ch then
+                                                  str ch
+                                              else
+                                                  "%" ^ hexIt ch)
+                   
 fun exp e =
     case e of
         EPrim (Prim.String s) =>
@@ -124,6 +143,27 @@
       | EWrite (EFfiApp ("Basis", "attrifyString", [e]), _) =>
         EFfiApp ("Basis", "attrifyString_w", [e])
 
+      | EFfiApp ("Basis", "urlifyInt", [(EPrim (Prim.Int n), _)]) =>
+        EPrim (Prim.String (urlifyInt n))
+      | EWrite (EFfiApp ("Basis", "urlifyInt", [(EPrim (Prim.Int n), _)]), loc) =>
+        EWrite (EPrim (Prim.String (urlifyInt n)), loc)
+      | EWrite (EFfiApp ("Basis", "urlifyInt", [e]), _) =>
+        EFfiApp ("Basis", "urlifyInt_w", [e])
+
+      | EFfiApp ("Basis", "urlifyFloat", [(EPrim (Prim.Float n), _)]) =>
+        EPrim (Prim.String (urlifyFloat n))
+      | EWrite (EFfiApp ("Basis", "urlifyFloat", [(EPrim (Prim.Float n), _)]), loc) =>
+        EWrite (EPrim (Prim.String (urlifyFloat n)), loc)
+      | EWrite (EFfiApp ("Basis", "urlifyFloat", [e]), _) =>
+        EFfiApp ("Basis", "urlifyFloat_w", [e])
+
+      | EFfiApp ("Basis", "urlifyString", [(EPrim (Prim.String s), _)]) =>
+        EPrim (Prim.String (urlifyString s))
+      | EWrite (EFfiApp ("Basis", "urlifyString", [(EPrim (Prim.String s), _)]), loc) =>
+        EWrite (EPrim (Prim.String (urlifyString s)), loc)
+      | EWrite (EFfiApp ("Basis", "urlifyString", [e]), _) =>
+        EFfiApp ("Basis", "urlifyString_w", [e])
+
       | _ => e
 
 and optExp e = #1 (U.Exp.map {typ = typ, exp = exp} e)