Failed attempt at implementing unicode chars.

This commit is contained in:
Erik Svedäng 2020-05-06 16:43:36 +02:00
parent 672c7e1b69
commit 5e6cbe4fd3
7 changed files with 20 additions and 15 deletions

View File

@ -74,7 +74,7 @@
(private getenv-)
(hidden getenv-)
(register getenv- (Fn [String] (Ptr Char)) "getenv")
(register getenv- (Fn [String] (Ptr CChar)) "getenv")
(defn getenv [s]
(let [e (getenv- s)]
(if (null? e)

View File

@ -1,5 +1,7 @@
(system-include "carp_string.h")
(register-type CChar "char")
(defmodule String
(register = (Fn [&String &String] Bool))
@ -10,7 +12,7 @@
(register copy (Fn [&String] String))
(register length (Fn [&String] Int))
(register cstr (Fn [&String] (Ptr Char)))
(register from-cstr (Fn [(Ptr Char)] String))
(register from-cstr (Fn [(Ptr CChar)] String))
(register str (Fn [&String] String))
(register prn (Fn [&String] String))
(register index-of (Fn [&String Char] Int))

View File

@ -1,24 +1,24 @@
bool Char__EQ_(char a, char b) {
bool Char__EQ_(Char a, Char b) {
return a == b;
}
bool Char__LT_(char a, char b) {
bool Char__LT_(Char a, Char b) {
return a < b;
}
bool Char__GT_(char a, char b) {
bool Char__GT_(Char a, Char b) {
return a > b;
}
int Char_to_MINUS_int(char c) {
return (int)(unsigned char)c;
int Char_to_MINUS_int(Char c) {
return (int)c;
}
char Char_from_MINUS_int(int i) {
return (char)i;
Char Char_from_MINUS_int(int i) {
return (Char)i;
}
char Char_copy(const char *c) {
Char Char_copy(const Char *c) {
return *c;
}

View File

@ -1,3 +1,5 @@
#include <wchar.h>
String String_allocate(int len, char byte) {
/* Allocate a string of length 'len + 1'
* setting the first len bytes to byte
@ -166,9 +168,9 @@ String Bool_format(const String *str, bool b) {
return buffer;
}
String Char_str(char c) {
String buffer = CARP_MALLOC(2);
sprintf(buffer, "%c", c);
String Char_str(Char c) {
String buffer = CARP_MALLOC(sizeof(Char) + 1);
swprintf((void*)buffer, 2, L"%c", c);
return buffer;
}

View File

@ -12,6 +12,7 @@ typedef SSIZE_T ssize_t;
typedef char *String;
typedef char *Pattern;
typedef int64_t Long;
typedef unsigned int Char;
#if defined NDEBUG
#define CHK_INDEX(i, n)

View File

@ -110,7 +110,7 @@ toC toCMode (Binder meta root) = emitterSrc (execState (visit startingIndent roo
'\t' -> "'\\t'"
'\n' -> "'\\n'"
'\\' -> "'\\\\'"
x -> ['\'', x, '\'']
x -> ['U', '\'', x, '\'']
Closure elem _ -> visit indent elem
Sym _ _ -> visitSymbol indent xobj
(Defn _) -> error (show (DontVisitObj xobj))

View File

@ -146,7 +146,7 @@ tyToCManglePtr _ LongTy = "Long"
tyToCManglePtr _ ByteTy = "uint8_t"
tyToCManglePtr _ StringTy = "String"
tyToCManglePtr _ PatternTy = "Pattern"
tyToCManglePtr _ CharTy = "char"
tyToCManglePtr _ CharTy = "Char"
tyToCManglePtr _ UnitTy = "void"
tyToCManglePtr _ (VarTy x) = x
tyToCManglePtr _ (FuncTy argTys retTy _) = "Fn__" ++ joinWithUnderscore (map (tyToCManglePtr True) argTys) ++ "_" ++ tyToCManglePtr True retTy