on master help sign in
Delimit escape codes properly.
5d5b1b3Matus Tejiscak
src/IRTS/CodegenC.hs+6−3
@@ -112,10 +112,13 @@ showCStr s = '"' : foldr ((++) . showChar) "\"" s
112 showChar '"' = "\\\""
112 showChar '"' = "\\\""
113 showChar '\\' = "\\\\"
113 showChar '\\' = "\\\\"
114 showChar c
114 showChar 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.
115− | ord c < 0x10 = "\\x0" ++ showHex (ord c) ""
118+ | ord c < 0x10 = "\"\"\\x0" ++ showHex (ord c) "\"\""
116− | ord c < 0x20 = "\\x" ++ showHex (ord c) ""
119+ | ord c < 0x20 = "\"\"\\x" ++ showHex (ord c) "\"\""
117 | ord c < 0x7f = [c] -- 0x7f = \DEL
120 | ord c < 0x7f = [c] -- 0x7f = \DEL
118− | ord c < 0x100 = "\\x" ++ showHex (ord c) ""
121+ | ord c < 0x100 = "\"\"\\x" ++ showHex (ord c) "\"\""
119 | otherwise = error $ "non-8-bit character in string literal: " ++ show c
122 | otherwise = error $ "non-8-bit character in string literal: " ++ show c
120
123
121bcc :: Int -> BC -> String
124bcc :: 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 @@
1module Main
1module Main
2
2
3main : IO ()
3main : IO ()
4−main = print . map ord . unpack $ "\x0a\x80\xC9\xFF"
4+main = print . map ord . unpack $ "\x0a\x80\xC9\xFF\n3\n4"