mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 13:37:57 +03:00
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:
parent
6593a64a19
commit
244df27942
@ -49,8 +49,8 @@ static size_t utf8encode(char *s, uint32_t c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Adapted from: http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
|
// Adapted from: http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
|
||||||
static const uint32_t UTF8_ACCEPT = 0;
|
#define UTF8_ACCEPT 0
|
||||||
static const uint32_t UTF8_REJECT = 12;
|
#define UTF8_REJECT 12
|
||||||
static uint32_t inline utf8decode(uint32_t *state, uint32_t *codep,
|
static uint32_t inline utf8decode(uint32_t *state, uint32_t *codep,
|
||||||
uint32_t byte) {
|
uint32_t byte) {
|
||||||
static const uint8_t utf8d[] = {
|
static const uint8_t utf8d[] = {
|
||||||
|
@ -4,6 +4,7 @@ module SymPath (SymPath(..)
|
|||||||
, consPath) where
|
, consPath) where
|
||||||
|
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
|
import Data.Char (isAscii, ord)
|
||||||
import Util
|
import Util
|
||||||
|
|
||||||
-- | The path to a binding
|
-- | The path to a binding
|
||||||
@ -17,7 +18,7 @@ instance Show SymPath where
|
|||||||
|
|
||||||
-- | Replaces symbols not allowed in C-identifiers.
|
-- | Replaces symbols not allowed in C-identifiers.
|
||||||
mangle :: String -> String
|
mangle :: String -> String
|
||||||
mangle = sreplace . creplace
|
mangle = ureplace . sreplace . creplace
|
||||||
where creplace = replaceChars (Map.fromList [('+', "_PLUS_")
|
where creplace = replaceChars (Map.fromList [('+', "_PLUS_")
|
||||||
,('-', "_MINUS_")
|
,('-', "_MINUS_")
|
||||||
,('*', "_MUL_")
|
,('*', "_MUL_")
|
||||||
@ -59,6 +60,7 @@ mangle = sreplace . creplace
|
|||||||
,("volatile", "_VOLATILE_")
|
,("volatile", "_VOLATILE_")
|
||||||
,("void", "_VOID_")
|
,("void", "_VOID_")
|
||||||
,("while", "_WHILE_")])
|
,("while", "_WHILE_")])
|
||||||
|
ureplace = concatMap (\c -> if isAscii c then pure c else "_U" ++ show (ord c) ++ "U_")
|
||||||
|
|
||||||
pathToC :: SymPath -> String
|
pathToC :: SymPath -> String
|
||||||
pathToC (SymPath modulePath name) =
|
pathToC (SymPath modulePath name) =
|
||||||
|
Loading…
Reference in New Issue
Block a user