on master help sign in
Delimit escape codes properly.
commit5d5b1b3e1273e65a02e88e7ce7eda4168a5a626c authorMatus Tejiscak <ziman@functor.sk> dateSun 19 Jan 2014, 14:58 (13 years ago) parent2bf16c9
3 files changed+8−5
src/IRTS/CodegenC.hs+6−3 test/reg031/expected+1−1 test/reg031/reg031.idr+1−1
src/IRTS/CodegenC.hs+6−3
@@ -112,10 +112,13 @@ showCStr s = '"' : foldr ((++) . showChar) "\"" s
112112 showChar '"' = "\\\""
113113 showChar '\\' = "\\\\"
114114 showChar c
115− | ord c < 0x10 = "\\x0" ++ showHex (ord c) ""
116− | ord c < 0x20 = "\\x" ++ showHex (ord c) ""
115+ -- Note: we need the double quotes around the codes because otherwise
116+ -- "\n3" would get encoded as "\x0a3", which is incorrect.
117+ -- Instead, we opt for "\x0a""3" and let the C compiler deal with it.
118+ | ord c < 0x10 = "\"\"\\x0" ++ showHex (ord c) "\"\""
119+ | ord c < 0x20 = "\"\"\\x" ++ showHex (ord c) "\"\""
117120 | ord c < 0x7f = [c] -- 0x7f = \DEL
118− | ord c < 0x100 = "\\x" ++ showHex (ord c) ""
121+ | ord c < 0x100 = "\"\"\\x" ++ showHex (ord c) "\"\""
119122 | otherwise = error $ "non-8-bit character in string literal: " ++ show c
120123
121124bcc :: Int -> BC -> String
test/reg031/expected+1−1
@@ -1 +1 @@
1−[10, -128, -55, -1]
1+[10, -128, -55, -1, 10, 51, 10, 52]
test/reg031/reg031.idr+1−1
@@ -1,4 +1,4 @@
11module Main
22
33main : IO ()
4−main = print . map ord . unpack $ "\x0a\x80\xC9\xFF"
4+main = print . map ord . unpack $ "\x0a\x80\xC9\xFF\n3\n4"