comparison src/mono_opt.sml @ 714:0f42461273cf

CHECK constraints
author Adam Chlipala <adamc@hcoop.net>
date Thu, 09 Apr 2009 15:30:15 -0400
parents bab524996fca
children e28637743279
comparison
equal deleted inserted replaced
713:baaae037e7f6 714:0f42461273cf
85 85
86 fun sqlifyInt n = attrifyInt n ^ "::int8" 86 fun sqlifyInt n = attrifyInt n ^ "::int8"
87 fun sqlifyFloat n = attrifyFloat n ^ "::float8" 87 fun sqlifyFloat n = attrifyFloat n ^ "::float8"
88 88
89 fun sqlifyString s = "E'" ^ String.translate (fn #"'" => "\\'" 89 fun sqlifyString s = "E'" ^ String.translate (fn #"'" => "\\'"
90 | ch => str ch) 90 | #"\\" => "\\\\"
91 | ch =>
92 if Char.isPrint ch then
93 str ch
94 else
95 "\\" ^ StringCvt.padLeft #"0" 3
96 (Int.fmt StringCvt.OCT (ord ch)))
91 (String.toString s) ^ "'::text" 97 (String.toString s) ^ "'::text"
92 98
93 fun exp e = 99 fun exp e =
94 case e of 100 case e of
95 EPrim (Prim.String s) => 101 EPrim (Prim.String s) =>
363 | ESignalBind ((ESignalReturn e1, loc), e2) => 369 | ESignalBind ((ESignalReturn e1, loc), e2) =>
364 optExp (EApp (e2, e1), loc) 370 optExp (EApp (e2, e1), loc)
365 371
366 | EJavaScript (_, _, SOME (e, _)) => e 372 | EJavaScript (_, _, SOME (e, _)) => e
367 373
374 | EFfiApp ("Basis", "checkString", [(EPrim (Prim.String s), loc)]) =>
375 let
376 fun uwify (cs, acc) =
377 case cs of
378 [] => String.concat (rev acc)
379 | #"(" :: #"_" :: cs => uwify (cs, "(uw_" :: acc)
380 | #" " :: #"_" :: cs => uwify (cs, " uw_" :: acc)
381 | #"'" :: cs =>
382 let
383 fun waitItOut (cs, acc) =
384 case cs of
385 [] => raise Fail "MonoOpt: Unterminated SQL string literal"
386 | #"'" :: cs => uwify (cs, "'" :: acc)
387 | #"\\" :: #"'" :: cs => waitItOut (cs, "\\'" :: acc)
388 | #"\\" :: #"\\" :: cs => waitItOut (cs, "\\\\" :: acc)
389 | c :: cs => waitItOut (cs, str c :: acc)
390 in
391 waitItOut (cs, "'" :: acc)
392 end
393 | c :: cs => uwify (cs, str c :: acc)
394
395 val s = case String.explode s of
396 #"_" :: cs => uwify (cs, ["uw_"])
397 | cs => uwify (cs, [])
398 in
399 EPrim (Prim.String s)
400 end
401
368 | _ => e 402 | _ => e
369 403
370 and optExp e = #1 (U.Exp.map {typ = typ, exp = exp} e) 404 and optExp e = #1 (U.Exp.map {typ = typ, exp = exp} e)
371 405
372 val optimize = U.File.map {typ = typ, exp = exp, decl = decl} 406 val optimize = U.File.map {typ = typ, exp = exp, decl = decl}