diff --git a/fco2/GenerateC.hs b/fco2/GenerateC.hs index 51c8b5f..0577c05 100644 --- a/fco2/GenerateC.hs +++ b/fco2/GenerateC.hs @@ -38,6 +38,8 @@ import Data.Maybe import Control.Monad.Writer import Control.Monad.Error import Control.Monad.State +import Numeric +import Text.Printf import qualified AST as A import Metadata @@ -195,9 +197,14 @@ genLiteralRepr (A.ArrayLiteral m es) sequence_ $ intersperse genComma (map genExpression es) tell ["}"] +hexToOct :: String -> String +hexToOct h = printf "%03o" (fst $ head $ readHex h) + convStringLiteral :: String -> String convStringLiteral [] = [] -convStringLiteral ('*':'#':a:b:s) = "\\x" ++ [a, b] ++ convStringLiteral s +convStringLiteral ('\\':s) = "\\\\" ++ convStringLiteral s +convStringLiteral ('*':'#':'0':'0':s) = "\\0" ++ convStringLiteral s +convStringLiteral ('*':'#':a:b:s) = "\\" ++ hexToOct [a, b] ++ convStringLiteral s convStringLiteral ('*':c:s) = convStringStar c ++ convStringLiteral s convStringLiteral (c:s) = c : convStringLiteral s diff --git a/fco2/TODO b/fco2/TODO index e2e7d63..24f95a3 100644 --- a/fco2/TODO +++ b/fco2/TODO @@ -15,5 +15,3 @@ handles different types.) Have a final pass that checks all the mangling has been done -- i.e. function calls have been removed, and so on. -String conversion is broken -- it needs to escape backslashes. - diff --git a/fco2/testcases/stringlit.occ b/fco2/testcases/stringlit.occ new file mode 100644 index 0000000..f45aa87 --- /dev/null +++ b/fco2/testcases/stringlit.occ @@ -0,0 +1,4 @@ +PROC P () + VAL []BYTE s IS "*c*n*t*s*X*#00*#A0\now": + SKIP +: