comparison src/prim.sml @ 1656:3e7c7e200713

Fix handling of quotes in generating C literals
author Adam Chlipala <adam@chlipala.net>
date Mon, 02 Jan 2012 17:08:39 -0500
parents 4d04cb89649b
children 4d64af730e35
comparison
equal deleted inserted replaced
1655:b694f9153faa 1656:3e7c7e200713
68 if size s >= n then 68 if size s >= n then
69 s 69 s
70 else 70 else
71 str ch ^ pad (n-1, ch, s) 71 str ch ^ pad (n-1, ch, s)
72 72
73 fun quoteDouble ch =
74 case ch of
75 #"'" => str ch
76 | _ => Char.toCString ch
77
78 fun toCChar ch =
79 case ch of
80 #"\"" => str ch
81 | _ => Char.toCString ch
82
83 val toCString = String.translate quoteDouble
84
73 fun p_t_GCC t = 85 fun p_t_GCC t =
74 case t of 86 case t of
75 Int n => string (int2s n) 87 Int n => string (int2s n)
76 | Float n => string (float2s n) 88 | Float n => string (float2s n)
77 | String s => box [string "\"", string (String.toCString s), string "\""] 89 | String s => box [string "\"", string (toCString s), string "\""]
78 | Char ch => box [string "'", string (Char.toCString ch), string "'"] 90 | Char ch => box [string "'", string (toCChar ch), string "'"]
79 91
80 fun equal x = 92 fun equal x =
81 case x of 93 case x of
82 (Int n1, Int n2) => n1 = n2 94 (Int n1, Int n2) => n1 = n2
83 | (Float n1, Float n2) => Real64.== (n1, n2) 95 | (Float n1, Float n2) => Real64.== (n1, n2)