comparison 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
comparison
equal deleted inserted replaced
119:7fdc146b2bc2 120:6230bdd122e7
49 | ch => if Char.isPrint ch then 49 | ch => if Char.isPrint ch then
50 str ch 50 str ch
51 else 51 else
52 "&#" ^ Int.toString (ord ch) ^ ";") 52 "&#" ^ Int.toString (ord ch) ^ ";")
53 53
54 val urlifyInt = attrifyInt
55 val urlifyFloat = attrifyFloat
56
57 fun hexIt ch =
58 let
59 val s = Int.fmt StringCvt.HEX (ord ch)
60 in
61 case size s of
62 0 => "00"
63 | 1 => "0" ^ s
64 | _ => s
65 end
66
67 val urlifyString = String.translate (fn #" " => "+"
68 | ch => if Char.isAlphaNum ch then
69 str ch
70 else
71 "%" ^ hexIt ch)
72
54 fun exp e = 73 fun exp e =
55 case e of 74 case e of
56 EPrim (Prim.String s) => 75 EPrim (Prim.String s) =>
57 let 76 let
58 val (_, chs) = 77 val (_, chs) =
122 | EWrite (EFfiApp ("Basis", "attrifyString", [(EPrim (Prim.String s), _)]), loc) => 141 | EWrite (EFfiApp ("Basis", "attrifyString", [(EPrim (Prim.String s), _)]), loc) =>
123 EWrite (EPrim (Prim.String (attrifyString s)), loc) 142 EWrite (EPrim (Prim.String (attrifyString s)), loc)
124 | EWrite (EFfiApp ("Basis", "attrifyString", [e]), _) => 143 | EWrite (EFfiApp ("Basis", "attrifyString", [e]), _) =>
125 EFfiApp ("Basis", "attrifyString_w", [e]) 144 EFfiApp ("Basis", "attrifyString_w", [e])
126 145
146 | EFfiApp ("Basis", "urlifyInt", [(EPrim (Prim.Int n), _)]) =>
147 EPrim (Prim.String (urlifyInt n))
148 | EWrite (EFfiApp ("Basis", "urlifyInt", [(EPrim (Prim.Int n), _)]), loc) =>
149 EWrite (EPrim (Prim.String (urlifyInt n)), loc)
150 | EWrite (EFfiApp ("Basis", "urlifyInt", [e]), _) =>
151 EFfiApp ("Basis", "urlifyInt_w", [e])
152
153 | EFfiApp ("Basis", "urlifyFloat", [(EPrim (Prim.Float n), _)]) =>
154 EPrim (Prim.String (urlifyFloat n))
155 | EWrite (EFfiApp ("Basis", "urlifyFloat", [(EPrim (Prim.Float n), _)]), loc) =>
156 EWrite (EPrim (Prim.String (urlifyFloat n)), loc)
157 | EWrite (EFfiApp ("Basis", "urlifyFloat", [e]), _) =>
158 EFfiApp ("Basis", "urlifyFloat_w", [e])
159
160 | EFfiApp ("Basis", "urlifyString", [(EPrim (Prim.String s), _)]) =>
161 EPrim (Prim.String (urlifyString s))
162 | EWrite (EFfiApp ("Basis", "urlifyString", [(EPrim (Prim.String s), _)]), loc) =>
163 EWrite (EPrim (Prim.String (urlifyString s)), loc)
164 | EWrite (EFfiApp ("Basis", "urlifyString", [e]), _) =>
165 EFfiApp ("Basis", "urlifyString_w", [e])
166
127 | _ => e 167 | _ => e
128 168
129 and optExp e = #1 (U.Exp.map {typ = typ, exp = exp} e) 169 and optExp e = #1 (U.Exp.map {typ = typ, exp = exp} e)
130 170
131 val optimize = U.File.map {typ = typ, exp = exp, decl = decl} 171 val optimize = U.File.map {typ = typ, exp = exp, decl = decl}