comparison src/prim.sml @ 1053:4eb1c4a1b057

Escaping UTF-8 in MonoOpt
author Adam Chlipala <adamc@hcoop.net>
date Thu, 03 Dec 2009 11:20:13 -0500
parents 280f81731426
children b06a2a65e670
comparison
equal deleted inserted replaced
1048:38411c2cd363 1053:4eb1c4a1b057
66 Int n => int2s' n 66 Int n => int2s' n
67 | Float n => float2s n 67 | Float n => float2s n
68 | String s => s 68 | String s => s
69 | Char ch => str ch 69 | Char ch => str ch
70 70
71 fun pad (n, ch, s) =
72 if size s >= n then
73 s
74 else
75 str ch ^ pad (n-1, ch, s)
76
77 val gccify = String.translate (fn ch => if Char.isPrint ch then
78 str ch
79 else
80 "\\" ^ pad (3, #"0", Int.fmt StringCvt.OCT (ord ch)))
81
71 fun p_t_GCC t = 82 fun p_t_GCC t =
72 case t of 83 case t of
73 Int n => string (int2s n) 84 Int n => string (int2s n)
74 | Float n => string (float2s n) 85 | Float n => string (float2s n)
75 | String s => box [string "\"", string (String.toString s), string "\""] 86 | String s => box [string "\"", string (gccify s), string "\""]
76 | Char ch => box [string "'", string (String.toString (str ch)), string "'"] 87 | Char ch => box [string "'", string (gccify (str ch)), string "'"]
77 88
78 fun equal x = 89 fun equal x =
79 case x of 90 case x of
80 (Int n1, Int n2) => n1 = n2 91 (Int n1, Int n2) => n1 = n2
81 | (Float n1, Float n2) => Real64.== (n1, n2) 92 | (Float n1, Float n2) => Real64.== (n1, n2)