Unicode fixes (#994)

* Some compilers (tcc) will complain switching on const values.

* Fix unicode example when compiling with -std=c99.
This commit is contained in:
jacereda 2020-11-22 06:45:26 +01:00 committed by GitHub
parent 6593a64a19
commit 244df27942
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -49,8 +49,8 @@ static size_t utf8encode(char *s, uint32_t c) {
}
// Adapted from: http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
static const uint32_t UTF8_ACCEPT = 0;
static const uint32_t UTF8_REJECT = 12;
#define UTF8_ACCEPT 0
#define UTF8_REJECT 12
static uint32_t inline utf8decode(uint32_t *state, uint32_t *codep,
uint32_t byte) {
static const uint8_t utf8d[] = {

View File

@ -4,6 +4,7 @@ module SymPath (SymPath(..)
, consPath) where
import qualified Data.Map as Map
import Data.Char (isAscii, ord)
import Util
-- | The path to a binding
@ -17,7 +18,7 @@ instance Show SymPath where
-- | Replaces symbols not allowed in C-identifiers.
mangle :: String -> String
mangle = sreplace . creplace
mangle = ureplace . sreplace . creplace
where creplace = replaceChars (Map.fromList [('+', "_PLUS_")
,('-', "_MINUS_")
,('*', "_MUL_")
@ -59,6 +60,7 @@ mangle = sreplace . creplace
,("volatile", "_VOLATILE_")
,("void", "_VOID_")
,("while", "_WHILE_")])
ureplace = concatMap (\c -> if isAscii c then pure c else "_U" ++ show (ord c) ++ "U_")
pathToC :: SymPath -> String
pathToC (SymPath modulePath name) =