mirror of
https://github.com/Ed94/metadesk.git
synced 2026-07-21 15:05:44 -07:00
Finished string.h/c pass (finallY)
moving on to the others...
This commit is contained in:
+15
-15
@@ -6,36 +6,37 @@
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Types & Spaces
|
||||
|
||||
typedef enum Dimension
|
||||
typedef enum Dimension Dimension;
|
||||
enum Dimension
|
||||
{
|
||||
Dimension_X,
|
||||
Dimension_Y,
|
||||
Dimension_Z,
|
||||
Dimension_W,
|
||||
}
|
||||
Dimension;
|
||||
};
|
||||
|
||||
typedef enum Side
|
||||
typedef enum Side Side;
|
||||
enum Side
|
||||
{
|
||||
Side_Invalid = -1,
|
||||
Side_Min,
|
||||
Side_Max,
|
||||
Side_COUNT,
|
||||
}
|
||||
Side;
|
||||
};
|
||||
#define side_flip(s) ((Side)(!(s)))
|
||||
|
||||
typedef enum Axis2
|
||||
typedef enum Axis2 Axis2;
|
||||
enum Axis2
|
||||
{
|
||||
Axis2_Invalid = -1,
|
||||
Axis2_X,
|
||||
Axis2_Y,
|
||||
Axis2_COUNT,
|
||||
}
|
||||
Axis2;
|
||||
};
|
||||
#define axis2_flip(a) ((Axis2)(!(a)))
|
||||
|
||||
typedef enum Corner
|
||||
typedef enum Corner Corner;
|
||||
enum Corner
|
||||
{
|
||||
Corner_Invalid = -1,
|
||||
Corner_00,
|
||||
@@ -43,10 +44,10 @@ typedef enum Corner
|
||||
Corner_10,
|
||||
Corner_11,
|
||||
Corner_COUNT
|
||||
}
|
||||
Corner;
|
||||
};
|
||||
|
||||
typedef enum Dir2
|
||||
typedef enum Dir2 Dir2;
|
||||
enum Dir2
|
||||
{
|
||||
Dir2_Invalid = -1,
|
||||
Dir2_Left,
|
||||
@@ -54,8 +55,7 @@ typedef enum Dir2
|
||||
Dir2_Right,
|
||||
Dir2_Down,
|
||||
Dir2_COUNT
|
||||
}
|
||||
Dir2;
|
||||
};
|
||||
|
||||
#define axis2_from_dir2(d) (((d) & 1) ? Axis2_Y : Axis2_X)
|
||||
#define side_from_dir2(d) (((d) < Dir2_Right) ? Side_Min : Side_Max)
|
||||
|
||||
+243
-186
@@ -2055,7 +2055,7 @@ FuzzyMatchRangeList
|
||||
fuzzy_match_find_alloc(AllocatorInfo ainfo, String8 needle, String8 haystack)
|
||||
{
|
||||
Arena* arena = arena_alloc(.backing = ainfo, .block_size = MB(1));
|
||||
TempArena scratch = scratch_begin(&arena, 1);
|
||||
TempArena scratch = temp_begin(&arena, 1);
|
||||
|
||||
String8List needles = str8_split(scratch.arena, needle, (U8*)" ", 1, 0);
|
||||
FuzzyMatchRangeList
|
||||
@@ -2089,7 +2089,7 @@ fuzzy_match_find_alloc(AllocatorInfo ainfo, String8 needle, String8 haystack)
|
||||
result.total_dim += dim_1u64(range);
|
||||
}
|
||||
}
|
||||
scratch_end(scratch);
|
||||
temp_end(scratch);
|
||||
arena_release(arena);
|
||||
return result;
|
||||
}
|
||||
@@ -2133,219 +2133,276 @@ fuzzy_match_range_list_copy_alloc(AllocatorInfo ainfo, FuzzyMatchRangeList* src)
|
||||
////////////////////////////////
|
||||
//~ NOTE(allen): Serialization Helpers
|
||||
|
||||
internal void
|
||||
str8_serial_begin(Arena *arena, String8List *srl){
|
||||
String8Node *node = push_array(arena, String8Node, 1);
|
||||
node->string.str = push_array_no_zero(arena, U8, 0);
|
||||
srl->first = srl->last = node;
|
||||
srl->node_count = 1;
|
||||
srl->total_size = 0;
|
||||
U64
|
||||
str8_serial_push_align(Arena* arena, String8List* srl, U64 align) {
|
||||
#if MD_DONT_MAP_ARENA_TO_ALLOCATOR_IMPL
|
||||
Assert(is_pow2(align));
|
||||
U64 pos = srl->total_size;
|
||||
U64 new_pos = align_pow2(pos, align);
|
||||
U64 size = (new_pos - pos);
|
||||
|
||||
if(size != 0)
|
||||
{
|
||||
U8* buf = push_array(arena, U8, size);
|
||||
|
||||
String8* str = &srl->last->string;
|
||||
if (str->str + str->size == buf) {
|
||||
srl->last->string.size += size;
|
||||
srl->total_size += size;
|
||||
}
|
||||
else {
|
||||
str8_list_push(arena, srl, str8(buf, size));
|
||||
}
|
||||
}
|
||||
return size;
|
||||
#else
|
||||
return str8_serial_alloc_align(arena_allocator(arena), srl, align);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_serial_end(Arena *arena, String8List *srl){
|
||||
U64 size = srl->total_size;
|
||||
U8 *out = push_array_no_zero(arena, U8, size);
|
||||
str8_serial_write_to_dst(srl, out);
|
||||
String8 result = str8(out, size);
|
||||
return result;
|
||||
void*
|
||||
str8_serial_push_size(Arena* arena, String8List* srl, U64 size) {
|
||||
#if MD_DONT_MAP_ARENA_TO_ALLOCATOR_IMPL
|
||||
void* result = 0;
|
||||
if(size != 0)
|
||||
{
|
||||
U8* buf = push_array_no_zero(arena, U8, size);
|
||||
String8* str = &srl->last->string;
|
||||
if (str->str + str->size == buf) {
|
||||
srl->last->string.size += size;
|
||||
srl->total_size += size;
|
||||
}
|
||||
else {
|
||||
str8_list_push(arena, srl, str8(buf, size));
|
||||
}
|
||||
result = buf;
|
||||
}
|
||||
return result;
|
||||
#else
|
||||
return str8_serial_alloc_size(arena_allocator(arena, srl, size));
|
||||
#endif
|
||||
}
|
||||
|
||||
internal void
|
||||
str8_serial_write_to_dst(String8List *srl, void *out){
|
||||
U8 *ptr = (U8*)out;
|
||||
for (String8Node *node = srl->first;
|
||||
node != 0;
|
||||
node = node->next){
|
||||
U64 size = node->string.size;
|
||||
MemoryCopy(ptr, node->string.str, size);
|
||||
ptr += size;
|
||||
}
|
||||
void
|
||||
str8_serial_push_u64(Arena* arena, String8List* srl, U64 x) {
|
||||
#if MD_DONT_MAP_ARENA_TO_ALLOCATOR_IMPL
|
||||
U8* buf = push_array_no_zero(arena, U8, 8);
|
||||
memory_copy(buf, &x, 8);
|
||||
String8* str = &srl->last->string;
|
||||
if (str->str + str->size == buf) {
|
||||
srl->last->string.size += 8;
|
||||
srl->total_size += 8;
|
||||
}
|
||||
else {
|
||||
str8_list_push(arena, srl, str8(buf, 8));
|
||||
}
|
||||
#else
|
||||
str8_serial_alloc_u64(arena_allocator(arena), srl, x);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal U64
|
||||
str8_serial_push_align(Arena *arena, String8List *srl, U64 align){
|
||||
Assert(IsPow2(align));
|
||||
|
||||
U64 pos = srl->total_size;
|
||||
U64 new_pos = AlignPow2(pos, align);
|
||||
U64 size = (new_pos - pos);
|
||||
|
||||
if(size != 0)
|
||||
{
|
||||
U8 *buf = push_array(arena, U8, size);
|
||||
|
||||
String8 *str = &srl->last->string;
|
||||
if (str->str + str->size == buf){
|
||||
srl->last->string.size += size;
|
||||
srl->total_size += size;
|
||||
}
|
||||
else{
|
||||
str8_list_push(arena, srl, str8(buf, size));
|
||||
}
|
||||
}
|
||||
return size;
|
||||
void
|
||||
str8_serial_push_u32(Arena* arena, String8List* srl, U32 x) {
|
||||
#if MD_DONT_MAP_ARENA_TO_ALLOCATOR_IMPL
|
||||
U8* buf = push_array_no_zero(arena, U8, 4);
|
||||
memory_copy(buf, &x, 4);
|
||||
String8 *str = &srl->last->string;
|
||||
if (str->str + str->size == buf) {
|
||||
srl->last->string.size += 4;
|
||||
srl->total_size += 4;
|
||||
}
|
||||
else {
|
||||
str8_list_push(arena, srl, str8(buf, 4));
|
||||
}
|
||||
#else
|
||||
str8_serial_alloc_u32(arena_allocator(arena), srl, x);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal void *
|
||||
str8_serial_push_size(Arena *arena, String8List *srl, U64 size)
|
||||
{
|
||||
void *result = 0;
|
||||
if(size != 0)
|
||||
{
|
||||
U8 *buf = push_array_no_zero(arena, U8, size);
|
||||
String8 *str = &srl->last->string;
|
||||
if (str->str + str->size == buf){
|
||||
srl->last->string.size += size;
|
||||
srl->total_size += size;
|
||||
}
|
||||
else{
|
||||
str8_list_push(arena, srl, str8(buf, size));
|
||||
}
|
||||
result = buf;
|
||||
}
|
||||
return result;
|
||||
U64
|
||||
str8_serial_alloc_align(AllocatorInfo ainfo, String8List* srl, U64 align) {
|
||||
Assert(is_pow2(align));
|
||||
U64 pos = srl->total_size;
|
||||
U64 new_pos = align_pow2(pos, align);
|
||||
U64 size = (new_pos - pos);
|
||||
|
||||
if(size != 0)
|
||||
{
|
||||
U8* buf = alloc_array(ainfo, U8, size);
|
||||
|
||||
String8* str = &srl->last->string;
|
||||
if (str->str + str->size == buf) {
|
||||
srl->last->string.size += size;
|
||||
srl->total_size += size;
|
||||
}
|
||||
else {
|
||||
str8_list_alloc(ainfo, srl, str8(buf, size));
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
internal void *
|
||||
str8_serial_push_data(Arena *arena, String8List *srl, void *data, U64 size){
|
||||
void *result = str8_serial_push_size(arena, srl, size);
|
||||
if(result != 0)
|
||||
{
|
||||
MemoryCopy(result, data, size);
|
||||
}
|
||||
return result;
|
||||
void*
|
||||
str8_serial_alloc_size(AllocatorInfo ainfo, String8List* srl, U64 size) {
|
||||
void* result = 0;
|
||||
if(size != 0)
|
||||
{
|
||||
U8* buf = alloc_array_no_zero(ainfo, U8, size);
|
||||
String8* str = &srl->last->string;
|
||||
if (str->str + str->size == buf) {
|
||||
srl->last->string.size += size;
|
||||
srl->total_size += size;
|
||||
}
|
||||
else {
|
||||
str8_list_alloc(ainfo, srl, str8(buf, size));
|
||||
}
|
||||
result = buf;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void
|
||||
str8_serial_push_data_list(Arena *arena, String8List *srl, String8Node *first){
|
||||
for (String8Node *node = first;
|
||||
node != 0;
|
||||
node = node->next){
|
||||
str8_serial_push_data(arena, srl, node->string.str, node->string.size);
|
||||
}
|
||||
void
|
||||
str8_serial_alloc_u64(AllocatorInfo ainfo, String8List* srl, U64 x) {
|
||||
U8* buf = alloc_array_no_zero(ainfo, U8, 8);
|
||||
memory_copy(buf, &x, 8);
|
||||
String8* str = &srl->last->string;
|
||||
if (str->str + str->size == buf) {
|
||||
srl->last->string.size += 8;
|
||||
srl->total_size += 8;
|
||||
}
|
||||
else {
|
||||
str8_list_alloc(ainfo, srl, str8(buf, 8));
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
str8_serial_push_u64(Arena *arena, String8List *srl, U64 x){
|
||||
U8 *buf = push_array_no_zero(arena, U8, 8);
|
||||
MemoryCopy(buf, &x, 8);
|
||||
String8 *str = &srl->last->string;
|
||||
if (str->str + str->size == buf){
|
||||
srl->last->string.size += 8;
|
||||
srl->total_size += 8;
|
||||
}
|
||||
else{
|
||||
str8_list_push(arena, srl, str8(buf, 8));
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
str8_serial_push_u32(Arena *arena, String8List *srl, U32 x){
|
||||
U8 *buf = push_array_no_zero(arena, U8, 4);
|
||||
MemoryCopy(buf, &x, 4);
|
||||
String8 *str = &srl->last->string;
|
||||
if (str->str + str->size == buf){
|
||||
srl->last->string.size += 4;
|
||||
srl->total_size += 4;
|
||||
}
|
||||
else{
|
||||
str8_list_push(arena, srl, str8(buf, 4));
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
str8_serial_push_u16(Arena *arena, String8List *srl, U16 x){
|
||||
str8_serial_push_data(arena, srl, &x, sizeof(x));
|
||||
}
|
||||
|
||||
internal void
|
||||
str8_serial_push_u8(Arena *arena, String8List *srl, U8 x){
|
||||
str8_serial_push_data(arena, srl, &x, sizeof(x));
|
||||
}
|
||||
|
||||
internal void
|
||||
str8_serial_push_cstr(Arena *arena, String8List *srl, String8 str){
|
||||
str8_serial_push_data(arena, srl, str.str, str.size);
|
||||
str8_serial_push_u8(arena, srl, 0);
|
||||
}
|
||||
|
||||
internal void
|
||||
str8_serial_push_string(Arena *arena, String8List *srl, String8 str){
|
||||
str8_serial_push_data(arena, srl, str.str, str.size);
|
||||
void
|
||||
str8_serial_push_u32(AllocatorInfo ainfo, String8List* srl, U32 x) {
|
||||
U8* buf = alloc_array_no_zero(ainfo, U8, 4);
|
||||
memory_copy(buf, &x, 4);
|
||||
String8 *str = &srl->last->string;
|
||||
if (str->str + str->size == buf) {
|
||||
srl->last->string.size += 4;
|
||||
srl->total_size += 4;
|
||||
}
|
||||
else {
|
||||
str8_list_alloc(ainfo, srl, str8(buf, 4));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Deserialization Helpers
|
||||
|
||||
internal U64
|
||||
str8_deserial_read(String8 string, U64 off, void *read_dst, U64 read_size, U64 granularity)
|
||||
{
|
||||
U64 bytes_left = string.size-Min(off, string.size);
|
||||
U64 actually_readable_size = Min(bytes_left, read_size);
|
||||
U64 legally_readable_size = actually_readable_size - actually_readable_size%granularity;
|
||||
if(legally_readable_size > 0)
|
||||
{
|
||||
MemoryCopy(read_dst, string.str+off, legally_readable_size);
|
||||
}
|
||||
return legally_readable_size;
|
||||
U64
|
||||
str8_deserial_read(String8 string, U64 off, void *read_dst, U64 read_size, U64 granularity) {
|
||||
U64 bytes_left = string.size - min(off, string.size);
|
||||
U64 actually_readable_size = min(bytes_left, read_size);
|
||||
U64 legally_readable_size = actually_readable_size - actually_readable_size % granularity;
|
||||
if(legally_readable_size > 0)
|
||||
{
|
||||
memory_copy(read_dst, string.str + off, legally_readable_size);
|
||||
}
|
||||
return legally_readable_size;
|
||||
}
|
||||
|
||||
internal U64
|
||||
str8_deserial_find_first_match(String8 string, U64 off, U16 scan_val)
|
||||
{
|
||||
U64 cursor = off;
|
||||
for (;;) {
|
||||
U16 val = 0;
|
||||
str8_deserial_read_struct(string, cursor, &val);
|
||||
if (val == scan_val) {
|
||||
break;
|
||||
}
|
||||
cursor += sizeof(val);
|
||||
}
|
||||
return cursor;
|
||||
U64
|
||||
str8_deserial_find_first_match(String8 string, U64 off, U16 scan_val) {
|
||||
U64 cursor = off;
|
||||
for (;;)
|
||||
{
|
||||
U16 val = 0;
|
||||
str8_deserial_read_struct(string, cursor, &val);
|
||||
if (val == scan_val) {
|
||||
break;
|
||||
}
|
||||
cursor += sizeof(val);
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
|
||||
internal void *
|
||||
str8_deserial_get_raw_ptr(String8 string, U64 off, U64 size)
|
||||
{
|
||||
void *raw_ptr = 0;
|
||||
if (off + size <= string.size) {
|
||||
raw_ptr = string.str + off;
|
||||
}
|
||||
return raw_ptr;
|
||||
U64
|
||||
str8_deserial_read_cstr(String8 string, U64 off, String8* cstr_out) {
|
||||
U64 cstr_size = 0;
|
||||
if (off < string.size) {
|
||||
U8* ptr = string.str + off;
|
||||
U8* cap = string.str + string.size;
|
||||
*cstr_out = str8_cstring_capped(ptr, cap);
|
||||
cstr_size = (cstr_out->size + 1);
|
||||
}
|
||||
return cstr_size;
|
||||
}
|
||||
|
||||
internal U64
|
||||
str8_deserial_read_cstr(String8 string, U64 off, String8 *cstr_out)
|
||||
U64
|
||||
str8_deserial_read_windows_utf16_string16(String8 string, U64 off, String16* str_out)
|
||||
{
|
||||
U64 cstr_size = 0;
|
||||
if (off < string.size) {
|
||||
U8 *ptr = string.str + off;
|
||||
U8 *cap = string.str + string.size;
|
||||
*cstr_out = str8_cstring_capped(ptr, cap);
|
||||
cstr_size = (cstr_out->size + 1);
|
||||
}
|
||||
return cstr_size;
|
||||
U64 null_off = str8_deserial_find_first_match(string, off, 0);
|
||||
U64 size = null_off - off;
|
||||
U16 *str = (U16*)str8_deserial_get_raw_ptr(string, off, size);
|
||||
U64 count = size / sizeof(*str);
|
||||
|
||||
*str_out = str16(str, count);
|
||||
|
||||
U64 read_size_with_null = size + sizeof(*str);
|
||||
return read_size_with_null;
|
||||
}
|
||||
|
||||
internal U64
|
||||
str8_deserial_read_windows_utf16_string16(String8 string, U64 off, String16 *str_out)
|
||||
{
|
||||
U64 null_off = str8_deserial_find_first_match(string, off, 0);
|
||||
U64 size = null_off - off;
|
||||
U16 *str = (U16 *)str8_deserial_get_raw_ptr(string, off, size);
|
||||
U64 count = size / sizeof(*str);
|
||||
*str_out = str16(str, count);
|
||||
|
||||
U64 read_size_with_null = size + sizeof(*str);
|
||||
return read_size_with_null;
|
||||
U64
|
||||
str8_deserial_read_uleb128(String8 string, U64 off, U64 *value_out) {
|
||||
U64 value = 0;
|
||||
U64 shift = 0;
|
||||
U64 cursor = off;
|
||||
for(;;)
|
||||
{
|
||||
U8 byte = 0;
|
||||
U64 bytes_read = str8_deserial_read_struct(string, cursor, &byte);
|
||||
if (bytes_read != sizeof(byte)) {
|
||||
break;
|
||||
}
|
||||
|
||||
U8 val = byte & 0x7fu;
|
||||
value |= ((U64)val) << shift;
|
||||
|
||||
cursor += bytes_read;
|
||||
shift += 7u;
|
||||
if ((byte & 0x80u) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(value_out != 0) { *value_out = value; }
|
||||
|
||||
U64 bytes_read = cursor - off;
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
internal U64
|
||||
str8_deserial_read_block(String8 string, U64 off, U64 size, String8 *block_out)
|
||||
U64
|
||||
str8_deserial_read_sleb128(String8 string, U64 off, S64 *value_out)
|
||||
{
|
||||
Rng1U64 range = rng_1u64(off, off + size);
|
||||
*block_out = str8_substr(string, range);
|
||||
return block_out->size;
|
||||
U64 value = 0;
|
||||
U64 shift = 0;
|
||||
U64 cursor = off;
|
||||
for(;;)
|
||||
{
|
||||
U8 byte;
|
||||
U64 bytes_read = str8_deserial_read_struct(string, cursor, &byte);
|
||||
if (bytes_read != sizeof(byte)) {
|
||||
break;
|
||||
}
|
||||
|
||||
U8 val = byte & 0x7fu;
|
||||
value |= ((U64)val) << shift;
|
||||
|
||||
cursor += bytes_read;
|
||||
shift += 7u;
|
||||
|
||||
if ((byte & 0x80u) == 0)
|
||||
{
|
||||
if (shift < sizeof(value) * 8 && (byte & 0x40u) != 0) {
|
||||
value |= -(S64)(1ull << shift);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (value_out != 0) { *value_out = value; }
|
||||
|
||||
U64 bytes_read = cursor - off;
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
+129
-24
@@ -888,35 +888,140 @@ MD_API FuzzyMatchRangeList fuzzy_match_range_list_copy_alloc(AllocatorInfo ainfo
|
||||
////////////////////////////////
|
||||
//~ NOTE(allen): Serialization Helpers
|
||||
|
||||
internal void str8_serial_write_to_dst (String8List* srl, void *out);
|
||||
|
||||
internal void str8_serial_begin (Arena* arena, String8List* srl);
|
||||
internal String8 str8_serial_end (Arena* arena, String8List* srl);
|
||||
internal U64 str8_serial_push_align (Arena* arena, String8List* srl, U64 align);
|
||||
internal void* str8_serial_push_size (Arena* arena, String8List* srl, U64 size);
|
||||
internal void* str8_serial_push_data (Arena* arena, String8List* srl, void* data, U64 size);
|
||||
internal void str8_serial_push_data_list(Arena* arena, String8List* srl, String8Node* first);
|
||||
internal void str8_serial_push_u64 (Arena* arena, String8List* srl, U64 x);
|
||||
internal void str8_serial_push_u32 (Arena* arena, String8List* srl, U32 x);
|
||||
internal void str8_serial_push_u16 (Arena* arena, String8List* srl, U16 x);
|
||||
internal void str8_serial_push_u8 (Arena* arena, String8List* srl, U8 x);
|
||||
internal void str8_serial_push_cstr (Arena* arena, String8List* srl, String8 str);
|
||||
internal void str8_serial_push_string (Arena* arena, String8List* srl, String8 str);
|
||||
|
||||
#define str8_serial_push_array(arena, srl, ptr, count) str8_serial_push_data (arena, srl, ptr, sizeof(*(ptr)) * (count))
|
||||
#define str8_serial_push_struct(arena, srl, ptr) str8_serial_push_array(arena, srl, ptr, 1)
|
||||
|
||||
inline void
|
||||
str8_serial_write_to_dst(String8List* srl, void* out) {
|
||||
U8* ptr = (U8*)out;
|
||||
for (String8Node *node = srl->first; node != 0; node = node->next)
|
||||
{
|
||||
U64 size = node->string.size;
|
||||
memory_copy(ptr, node->string.str, size);
|
||||
ptr += size;
|
||||
}
|
||||
}
|
||||
|
||||
void str8_serial_begin (Arena* arena, String8List* srl);
|
||||
String8 str8_serial_end (Arena* arena, String8List* srl);
|
||||
MD_API U64 str8_serial_push_align (Arena* arena, String8List* srl, U64 align);
|
||||
MD_API void* str8_serial_push_size (Arena* arena, String8List* srl, U64 size);
|
||||
void* str8_serial_push_data (Arena* arena, String8List* srl, void* data, U64 size);
|
||||
void str8_serial_push_data_list(Arena* arena, String8List* srl, String8Node* first);
|
||||
MD_API void str8_serial_push_u64 (Arena* arena, String8List* srl, U64 x);
|
||||
MD_API void str8_serial_push_u32 (Arena* arena, String8List* srl, U32 x);
|
||||
void str8_serial_push_u16 (Arena* arena, String8List* srl, U16 x);
|
||||
void str8_serial_push_u8 (Arena* arena, String8List* srl, U8 x);
|
||||
void str8_serial_push_cstr (Arena* arena, String8List* srl, String8 str);
|
||||
void str8_serial_push_string (Arena* arena, String8List* srl, String8 str);
|
||||
|
||||
inline void
|
||||
str8_serial_begin(Arena* arena, String8List* srl){
|
||||
String8Node* node = push_array(arena, String8Node, 1);
|
||||
node->string.str = push_array_no_zero(arena, U8, 0);
|
||||
srl->first = srl->last = node;
|
||||
srl->node_count = 1;
|
||||
srl->total_size = 0;
|
||||
}
|
||||
|
||||
inline String8
|
||||
str8_serial_end(Arena* arena, String8List* srl) {
|
||||
U64 size = srl->total_size;
|
||||
U8* out = push_array_no_zero(arena, U8, size);
|
||||
str8_serial_write_to_dst(srl, out);
|
||||
String8 result = str8(out, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void*
|
||||
str8_serial_push_data(Arena* arena, String8List* srl, void* data, U64 size){
|
||||
void* result = str8_serial_push_size(arena, srl, size);
|
||||
if(result != 0) {
|
||||
memory_copy(result, data, size);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void
|
||||
str8_serial_push_data_list(Arena* arena, String8List* srl, String8Node* first){
|
||||
for (String8Node* node = first; node != 0; node = node->next) {
|
||||
str8_serial_push_data(arena, srl, node->string.str, node->string.size);
|
||||
}
|
||||
}
|
||||
|
||||
inline void str8_serial_push_u16(Arena* arena, String8List* srl, U16 x) { str8_serial_push_data(arena, srl, &x, sizeof(x)); }
|
||||
inline void str8_serial_push_u8 (Arena* arena, String8List* srl, U8 x) { str8_serial_push_data(arena, srl, &x, sizeof(x)); }
|
||||
|
||||
inline void str8_serial_push_cstr (Arena* arena, String8List* srl, String8 str) { str8_serial_push_data(arena, srl, str.str, str.size); str8_serial_push_u8(arena, srl, 0); }
|
||||
inline void str8_serial_push_string(Arena* arena, String8List* srl, String8 str) { str8_serial_push_data(arena, srl, str.str, str.size); }
|
||||
|
||||
void str8_serial_begin_alloc (AllocatorInfo ainfo, String8List* srl);
|
||||
String8 str8_serial_end_alloc (AllocatorInfo ainfo, String8List* srl);
|
||||
MD_API U64 str8_serial_alloc_align (AllocatorInfo ainfo, String8List* srl, U64 align);
|
||||
MD_API void* str8_serial_alloc_size (AllocatorInfo ainfo, String8List* srl, U64 size);
|
||||
void* str8_serial_alloc_data (AllocatorInfo ainfo, String8List* srl, void* data, U64 size);
|
||||
void str8_serial_alloc_data_list(AllocatorInfo ainfo, String8List* srl, String8Node* first);
|
||||
MD_API void str8_serial_alloc_u64 (AllocatorInfo ainfo, String8List* srl, U64 x);
|
||||
MD_API void str8_serial_alloc_u32 (AllocatorInfo ainfo, String8List* srl, U32 x);
|
||||
void str8_serial_alloc_u16 (AllocatorInfo ainfo, String8List* srl, U16 x);
|
||||
void str8_serial_alloc_u8 (AllocatorInfo ainfo, String8List* srl, U8 x);
|
||||
void str8_serial_alloc_cstr (AllocatorInfo ainfo, String8List* srl, String8 str);
|
||||
void str8_serial_alloc_string (AllocatorInfo ainfo, String8List* srl, String8 str);
|
||||
|
||||
inline void
|
||||
str8_serial_begin(AllocatorInfo ainfo, String8List* srl) {
|
||||
String8Node* node = alloc_array(ainfo, String8Node, 1);
|
||||
node->string.str = alloc_array_no_zero(ainfo, U8, 0);
|
||||
srl->first = srl->last = node;
|
||||
srl->node_count = 1;
|
||||
srl->total_size = 0;
|
||||
}
|
||||
|
||||
inline String8
|
||||
str8_serial_end(AllocatorInfo ainfo, String8List* srl) {
|
||||
U64 size = srl->total_size;
|
||||
U8* out = alloc_array_no_zero(ainfo, U8, size);
|
||||
str8_serial_write_to_dst(srl, out);
|
||||
String8 result = str8(out, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void*
|
||||
str8_serial_push_data(AllocatorInfo ainfo, String8List* srl, void* data, U64 size){
|
||||
void* result = str8_serial_alloc_size(ainfo, srl, size);
|
||||
if(result != 0) {
|
||||
memory_copy(result, data, size);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void
|
||||
str8_serial_push_data_list(AllocatorInfo ainfo, String8List* srl, String8Node* first){
|
||||
for (String8Node* node = first; node != 0; node = node->next) {
|
||||
str8_serial_alloc_data(ainfo, srl, node->string.str, node->string.size);
|
||||
}
|
||||
}
|
||||
|
||||
inline void str8_serial_alloc_u16(AllocatorInfo ainfo, String8List* srl, U16 x) { str8_serial_alloc_data(ainfo, srl, &x, sizeof(x)); }
|
||||
inline void str8_serial_alloc_u8 (AllocatorInfo ainfo, String8List* srl, U8 x) { str8_serial_alloc_data(ainfo, srl, &x, sizeof(x)); }
|
||||
|
||||
inline void str8_serial_push_cstr (AllocatorInfo ainfo, String8List* srl, String8 str) { str8_serial_alloc_data(ainfo, srl, str.str, str.size); str8_serial_alloc_u8(ainfo, srl, 0); }
|
||||
inline void str8_serial_push_string(AllocatorInfo ainfo, String8List* srl, String8 str) { str8_serial_alloc_data(ainfo, srl, str.str, str.size); }
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Deserialization Helpers
|
||||
|
||||
internal U64 str8_deserial_read (String8 string, U64 off, void* read_dst, U64 read_size, U64 granularity);
|
||||
internal U64 str8_deserial_find_first_match (String8 string, U64 off, U16 scan_val);
|
||||
internal void* str8_deserial_get_raw_ptr (String8 string, U64 off, U64 size);
|
||||
internal U64 str8_deserial_read_cstr (String8 string, U64 off, String8* cstr_out);
|
||||
internal U64 str8_deserial_read_windows_utf16_string16(String8 string, U64 off, String16* str_out);
|
||||
internal U64 str8_deserial_read_block (String8 string, U64 off, U64 size, String8* block_out);
|
||||
internal U64 str8_deserial_read_uleb128 (String8 string, U64 off, U64* value_out);
|
||||
internal U64 str8_deserial_read_sleb128 (String8 string, U64 off, S64* value_out);
|
||||
|
||||
#define str8_deserial_read_array(string, off, ptr, count) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr)) * (count), sizeof( *(ptr)))
|
||||
#define str8_deserial_read_struct(string, off, ptr) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr)), sizeof( *(ptr)))
|
||||
|
||||
MD_API U64 str8_deserial_read (String8 string, U64 off, void* read_dst, U64 read_size, U64 granularity);
|
||||
MD_API U64 str8_deserial_find_first_match (String8 string, U64 off, U16 scan_val);
|
||||
void* str8_deserial_get_raw_ptr (String8 string, U64 off, U64 size);
|
||||
MD_API U64 str8_deserial_read_cstr (String8 string, U64 off, String8* cstr_out);
|
||||
MD_API U64 str8_deserial_read_windows_utf16_string16(String8 string, U64 off, String16* str_out);
|
||||
U64 str8_deserial_read_block (String8 string, U64 off, U64 size, String8* block_out);
|
||||
MD_API U64 str8_deserial_read_uleb128 (String8 string, U64 off, U64* value_out);
|
||||
MD_API U64 str8_deserial_read_sleb128 (String8 string, U64 off, S64* value_out);
|
||||
|
||||
inline void* str8_deserial_get_raw_ptr(String8 string, U64 off, U64 size) { void* raw_ptr = 0; if (off + size <= string.size) { raw_ptr = string.str + off; } return raw_ptr; }
|
||||
inline U64 str8_deserial_read_block (String8 string, U64 off, U64 size, String8* block_out) { Rng1U64 range = rng_1u64(off, off + size); *block_out = str8_substr(string, range); return block_out->size; }
|
||||
|
||||
@@ -25,8 +25,8 @@ struct TCTX
|
||||
////////////////////////////////
|
||||
// NOTE(allen): Thread Context Functions
|
||||
|
||||
MD_API void tctx_init_and_equip(TCTX *tctx);
|
||||
MD_API void tctx_init_and_equip_ainfos(TCTX *tctx, AllocatorInfo ainfos[2]);
|
||||
MD_API void tctx_init_and_equip(TCTX* tctx);
|
||||
MD_API void tctx_init_and_equip_ainfos(TCTX* tctx, AllocatorInfo ainfos[2]);
|
||||
MD_API void tctx_release(void);
|
||||
MD_API TCTX* tctx_get_equipped(void);
|
||||
|
||||
@@ -58,7 +58,7 @@ tctx_get_thread_name(void) {
|
||||
}
|
||||
|
||||
inline void
|
||||
tctx_write_srcloc(char *file_name, U64 line_number){
|
||||
tctx_write_srcloc(char* file_name, U64 line_number){
|
||||
TCTX *tctx = tctx_get_equipped();
|
||||
tctx->file_name = file_name;
|
||||
tctx->line_number = line_number;
|
||||
|
||||
+12
-11
@@ -6,26 +6,28 @@
|
||||
////////////////////////////////
|
||||
//~ rjf: Toolchain/Environment Enums
|
||||
|
||||
typedef enum OperatingSystem
|
||||
typedef enum OperatingSystem OperatingSystem;
|
||||
enum OperatingSystem
|
||||
{
|
||||
OperatingSystem_Null,
|
||||
OperatingSystem_Windows,
|
||||
OperatingSystem_Linux,
|
||||
OperatingSystem_Mac,
|
||||
OperatingSystem_COUNT,
|
||||
}
|
||||
OperatingSystem;
|
||||
};
|
||||
|
||||
typedef enum ImageType
|
||||
typedef enum ImageType ImageType;
|
||||
enum ImageType
|
||||
{
|
||||
Image_Null,
|
||||
Image_CoffPe,
|
||||
Image_Elf32,
|
||||
Image_Elf64,
|
||||
Image_Macho
|
||||
} ImageType;
|
||||
};
|
||||
|
||||
typedef enum Arch
|
||||
typedef enum Arch Arch;
|
||||
enum Arch
|
||||
{
|
||||
Arch_Null,
|
||||
Arch_x64,
|
||||
@@ -33,18 +35,17 @@ typedef enum Arch
|
||||
Arch_arm64,
|
||||
Arch_arm32,
|
||||
Arch_COUNT,
|
||||
}
|
||||
Arch;
|
||||
};
|
||||
|
||||
typedef enum Compiler
|
||||
typedef enum Compiler Compiler;
|
||||
enum Compiler
|
||||
{
|
||||
Compiler_Null,
|
||||
Compiler_msvc,
|
||||
Compiler_gcc,
|
||||
Compiler_clang,
|
||||
Compiler_COUNT,
|
||||
}
|
||||
Compiler;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Toolchain/Environment Enum Functions
|
||||
|
||||
Reference in New Issue
Block a user