Many changes, building many targets at the same time

This commit is contained in:
Krzosa Karol
2024-01-27 19:32:12 +01:00
parent e39cd78546
commit 43f770b790
18 changed files with 386 additions and 58 deletions

View File

@@ -1,6 +1,21 @@
#include "clexer.h"
#include <stdarg.h>
/*
- I'm pretty sure I can remove allocations for most of the current functions.
- I also can fix ResolvePath stuff so that it uses string+len and doesn't need allocations
- Add lexing options like in stb_c_lexer.h
Instead of AND_CL_STRING_TERMINATE_ON_NEW_LINE he is doing some weird cool stuff with redefining
https://github.com/nothings/stb/blob/master/stb_c_lexer.h
CL_MULTILINE_SSTRINGS
CL_DOLLAR_IDENT
- Add proper string parsing, as additional function, CL_ParseString() or something, this is the only one that would need allocations
*/
#ifndef CL_PRIVATE_FUNCTION
#if defined(__GNUC__) || defined(__clang__)
#define CL_PRIVATE_FUNCTION __attribute__((unused)) static

View File

@@ -31,7 +31,7 @@ IO_StaticFunc int IO_Strlen(char *string) {
return len;
}
void (*IO_User_OutputMessage)(int kind, char *file, int line, char *str, int len);
void (*IO_User_OutputMessage)(int kind, const char *file, int line, char *str, int len);
IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) {
va_list args1;
@@ -83,7 +83,7 @@ IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) {
return ret == IO_ErrorResult_Break;
}
IO_API void IO__Printf(int kind, char *file, int line, const char *msg, ...) {
IO_API void IO__Printf(int kind, const char *file, int line, const char *msg, ...) {
// First try to use a static buffer. That can fail because the message
// can be bigger then the buffer. Allocate enough memory to fit in that
// case.
@@ -127,7 +127,7 @@ IO_API bool IO__FatalError(char *msg) {
return result == IO_ErrorResult_Break;
}
IO_API void IO_Print(int kind, char *file, int line, char *msg, int len) {
IO_API void IO_Print(int kind, const char *file, int line, char *msg, int len) {
if (IO_User_OutputMessage) {
IO_User_OutputMessage(kind, file, line, msg, len);
}

View File

@@ -31,7 +31,7 @@ typedef enum IO_ErrorResult {
#define IO__PrintfFormat(fmt, va)
#endif
extern void (*IO_User_OutputMessage)(int kind, char *file, int line, char *str, int len);
extern void (*IO_User_OutputMessage)(int kind, const char *file, int line, char *str, int len);
#define IO__STRINGIFY(x) #x
#define IO__TOSTRING(x) IO__STRINGIFY(x)
@@ -74,9 +74,9 @@ extern void (*IO_User_OutputMessage)(int kind, char *file, int line, char *str,
#define IO_Todo() IO_FatalError("This codepath is not implemented yet")
IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) IO__PrintfFormat(3, 4);
IO_API void IO__Printf(int kind, char *file, int line, const char *msg, ...) IO__PrintfFormat(4, 5);
IO_API void IO__Printf(int kind, const char *file, int line, const char *msg, ...) IO__PrintfFormat(4, 5);
IO_API bool IO__FatalError(char *msg);
IO_API void IO_Print(int kind, char *file, int line, char *msg, int len);
IO_API void IO_Print(int kind, const char *file, int line, char *msg, int len);
IO_API void IO_OutputMessage(char *str, int len);
IO_API IO_ErrorResult IO_OutputError(char *str, int len);
IO_API void IO_Exit(int error_code);

View File

@@ -103,13 +103,13 @@
#endif
#if OS_WINDOWS
#define OS_NAME "Windows"
#define OS_NAME "windows"
#elif OS_LINUX
#define OS_NAME "Linux"
#define OS_NAME "linux"
#elif OS_MAC
#define OS_NAME "MacOS"
#define OS_NAME "mac_os"
#else
#error couldn't figure out OS
#error couldnt figure out OS
#endif
// #if COMPILER_CLANG

View File

@@ -529,3 +529,38 @@ S8_API S8_String S8_AddF(S8_Allocator allocator, S8_List *list, const char *str,
S8_AddNode(allocator, list, result);
return result;
}
#ifdef UTF_HEADER
S8_API S16_String S8_ToWidecharEx(S8_Allocator allocator, S8_String string) {
S8_ASSERT(sizeof(wchar_t) == 2);
wchar_t *buffer = (wchar_t *)S8_ALLOCATE(allocator, sizeof(wchar_t) * (string.len + 1));
int64_t size = UTF_CreateWidecharFromChar(buffer, string.len + 1, string.str, string.len);
S16_String result = {buffer, size};
return result;
}
S8_API wchar_t *S8_ToWidechar(S8_Allocator allocator, S8_String string) {
S16_String result = S8_ToWidecharEx(allocator, string);
return result.str;
}
S8_API S8_String S8_FromWidecharEx(S8_Allocator allocator, wchar_t *wstring, int64_t wsize) {
S8_ASSERT(sizeof(wchar_t) == 2);
int64_t buffer_size = (wsize + 1) * 2;
char *buffer = (char *)S8_ALLOCATE(allocator, buffer_size);
int64_t size = UTF_CreateCharFromWidechar(buffer, buffer_size, wstring, wsize);
S8_String result = S8_Make(buffer, size);
S8_ASSERT(size < buffer_size);
return result;
}
S8_API S8_String S8_FromWidechar(S8_Allocator allocator, wchar_t *wstring) {
int64_t size = S8_WideLength(wstring);
S8_String result = S8_FromWidecharEx(allocator, wstring, size);
return result;
}
#endif

View File

@@ -80,6 +80,11 @@ struct S8_List {
#endif
};
typedef struct S16_String {
wchar_t *str;
int64_t len;
} S16_String;
typedef int S8_FindFlag;
enum {
S8_FindFlag_None = 0,
@@ -177,6 +182,11 @@ S8_API S8_Node *S8_AddNode(S8_Allocator allocator, S8_List *list, S8_String stri
S8_API S8_Node *S8_Add(S8_Allocator allocator, S8_List *list, S8_String string);
S8_API S8_String S8_AddF(S8_Allocator allocator, S8_List *list, const char *str, ...) S8__PrintfFormat(3, 4);
S8_API S16_String S8_ToWidecharEx(S8_Allocator allocator, S8_String string);
S8_API wchar_t *S8_ToWidechar(S8_Allocator allocator, S8_String string);
S8_API S8_String S8_FromWidecharEx(S8_Allocator allocator, wchar_t *wstring, int64_t wsize);
S8_API S8_String S8_FromWidechar(S8_Allocator allocator, wchar_t *wstring);
#if defined(__cplusplus)
inline S8_String operator""_s(const char *str, size_t size) { return {(char *)str, (int64_t)size}; }
inline bool operator==(S8_String a, S8_String b) { return S8_AreEqual(a, b, 0); }

View File

@@ -159,6 +159,9 @@ UTF_API int64_t UTF_CreateCharFromWidechar(char *buffer, int64_t buffer_size, wc
return outlen;
}
// @todo: the api here is from one side cool but from other kind of weird
// int64_t size = UTF_CreateWidecharFromChar(wcmd, cmd.len + 1, cmd.str, cmd.len);
// the "+ 1" part is bothering me, but if it wrote one past buffer_size, that would be worse
UTF_API int64_t UTF_CreateWidecharFromChar(wchar_t *buffer, int64_t buffer_size, char *in, int64_t inlen) {
int64_t outlen = 0;
for (int64_t i = 0; i < inlen;) {