diff --git a/demo.str_cache.c b/demo.str_cache.c index f758c79..8dcda93 100644 --- a/demo.str_cache.c +++ b/demo.str_cache.c @@ -172,7 +172,7 @@ It will return a result in a composite struct: FileOpResult; which may be expand typedef struct FileOpResult FileOpResult; typedef struct Opts__read_file_contents Opts__read_file_contents; -void api_file_read_contents(FileOpResult* result, Str8 path, Opts__read_file_contents* opts); +void file_read_contents_api(FileOpResult* result, Str8 path, Opts__read_file_contents* opts); FileOpResult file__read_contents ( Str8 path, Opts__read_file_contents* opts); #define file_read_contents(path, ...) file__read_contents(path, & (Opts__read_file_contents){__VA_ARGS__} ) @@ -256,7 +256,7 @@ typedef U8 FMem_64KB [ KILOBTYES(64) ]; #define fmem_slice(mem) (SliceByte) { mem, size_of(mem) } // We'll be using an intrinsic for copying memory: -void* memory_copy(void* dest, void const* src, USIZE length) +void* memory_copy(void* restrict dest, void const* restrict src, USIZE length) { if (dest == nullptr || src == nullptr || length == 0) { return nullptr; @@ -323,7 +323,7 @@ struct Opts__read_file_contents B32 zero_backing; }; -void api_file_read_contents(FileOpResult* result, Str8 path, Opts__read_file_contents* opts) +void file_read_contents_api(FileOpResult* result, Str8 path, Opts__read_file_contents* opts) { assert(result != nullptr); assert(opts != nullptr); @@ -399,7 +399,7 @@ void api_file_read_contents(FileOpResult* result, Str8 path, Opts__read_file_con inline FileOpResult file__read_contents(Str8 path, Opts__read_file_contents* opts) { FileOpResult result; - api_file_read_contents(& result, path, opts); + file_read_contents_api(& result, path, opts); return result; } @@ -430,7 +430,7 @@ returning a WATL_LexInfo for providing user info on how the operation went. typedef struct WATL_LexInfo WATL_LexInfo; typedef struct Opts__watl_lex Opts__watl_lex; -void api_watl_lex(WATL_LexInfo* info, Str8 source, Opts__watl_lex* opts); +void watl_lex_api(WATL_LexInfo* info, Str8 source, Opts__watl_lex* opts); WATL_LexInfo watl__lex ( Str8 source, Opts__watl_lex* opts); #define watl_lex(source, ...) watl__lex(source, &(Opts__watl_lex){__VA_ARGS__}) @@ -510,7 +510,7 @@ inline void api_farena_init(FArena* arena, SliceByte mem) { arena->start = mem.ptr; arena->capacity = mem.len; - arena->used = 0; + arena->used = 0; } inline FArena farena_init(SliceByte mem) { FArena arena; api_farena_init(& arena, mem); return arena; } @@ -519,7 +519,7 @@ void* farena__push(FArena* arena, USIZE type_size, USIZE amount, Str8 dbg_typena USIZE to_commit = type_size * amount; USIZE unused = arena->capacity - arena->used; assert(to_commit <= unused); - void* ptr = cast(void*, cast(USIZE, arena->start) + arena->used); + void* ptr = cast(void*, cast(USIZE, arena->start) + arena->used); arena->used += to_commit; return ptr; } @@ -552,7 +552,7 @@ struct Opts__watl_lex { }; // We are assuming everything is utf8-ascii. -void api_watl_lex(WATL_LexInfo* info, Str8 source, Opts__watl_lex* opts) +void watl_lex_api(WATL_LexInfo* info, Str8 source, Opts__watl_lex* opts) { assert(info != nullptr); slice_assert(source); @@ -603,16 +603,16 @@ void api_watl_lex(WATL_LexInfo* info, Str8 source, Opts__watl_lex* opts) default: { if (was_formatting) { - tok = farena_push(arena, WATL_Tok); - tok->code = cursor; + tok = farena_push(arena, WATL_Tok); + tok->code = cursor; was_formatting = false; } cursor += 1; } break; } - prev = cursor - 1; - code = * cursor; + prev = cursor - 1; + code = * cursor; } info->tokens.ptr = arena.start; info->tokens.len = arena.used / size_of(WATL_Tok*); @@ -623,7 +623,7 @@ void api_watl_lex(WATL_LexInfo* info, Str8 source, Opts__watl_lex* opts) inline WATL_LexInfo watl__lex(Str8 source, Opts__watl_lex* opts) { WATL_LexInfo result = {0}; - api_watl_lex(& result, source, opts); + watl_lex_api(& result, source, opts); return result; } @@ -673,7 +673,7 @@ Next we'll parse these tokens into a rudimentary WATL Abstract Syntax Tree. typedef struct WATL_ParseInfo WATL_ParseInfo; typedef struct Opts__watl_parse Opts__watl_parse; -void api_watl_parse(WATL_ParseInfo* info, WATL_SliceTok tokens, Opts__watl_parse* opts); +void watl_parse_api(WATL_ParseInfo* info, WATL_SliceTok tokens, Opts__watl_parse* opts); WATL_ParseInfo watl__parse ( WATL_SliceTok tokens, Opts__watl_parse* opts); #define watl_parse(tokens, ...) watl__parse(tokens, & (Opts__watl_parse) {__VA_ARGS__}) @@ -682,7 +682,7 @@ For the sake of the exercise, we'll be eliminating the association with the file */ #pragma region Str8Cache typedef struct Str8Cache Str8Cache; -void api_str8cache_init(Str8Cache* cache, SliceByte mem_strs, SliceByte mem_slots, SliceByte mem_table); +void str8cache_init_api(Str8Cache* cache, SliceByte mem_strs, SliceByte mem_slots, SliceByte mem_table); Str8Cache str8cache_init ( SliceByte mem_strs, SliceByte mem_slots, SliceByte mem_table); // A cache like this relies on tabling string entires utiliszing an index derived from a hashed ID. @@ -728,9 +728,9 @@ struct Str8Cache { Str8Cache_SliceSlot table; }; -Str8Cache str8cache_init(SliceByte mem_strs, SliceByte mem_slots, SliceByte mem_table) { Str8Cache cache; api_str8cache_init(& cache, mem_strs, mem_slots, mem_table); return cache; } +Str8Cache str8cache_init(SliceByte mem_strs, SliceByte mem_slots, SliceByte mem_table) { Str8Cache cache; str8cache_init_api(& cache, mem_strs, mem_slots, mem_table); return cache; } inline -void api_str8cache_init(Str8Cache* cache, SliceByte mem_strs, SliceByte mem_slots, SliceByte mem_table) { +void str8cache_init_api(Str8Cache* cache, SliceByte mem_strs, SliceByte mem_slots, SliceByte mem_table) { assert(cache != nullptr); slice_assert(mem_strs); slice_assert(mem_slots); @@ -825,7 +825,7 @@ Str8* str8cache_set(Str8Cache* cache, U64 key, Str8 value) slice_copy(mem, value); slot->next->value = (Str8){mem.ptr, mem.len / size_of(char)}; } - slot->next->value = value; + slot->next->value = value; slot->next->key = key; slot->next->occupied = true; return & slot->next->value; @@ -872,8 +872,8 @@ struct WATL_SliceLine { #if defined(DEMO__WATL_PARSE_V1) || defined(DEMO__WATL_DUMP_V1) struct Opts__watl_parse { - SliceByte backing_nodes; - SliceByte backing_lines; + SliceByte backing_nodes; + SliceByte backing_lines; Str8Cache* str_cache; }; @@ -881,7 +881,7 @@ struct WATL_ParseInfo { WATL_SliceLine lines; }; -void api_watl_parse(WATL_ParseInfo* info, WATL_SliceTok tokens, Opts__watl_parse* opts) +void watl_parse_api(WATL_ParseInfo* info, WATL_SliceTok tokens, Opts__watl_parse* opts) { assert(info != nullptr); slice_assert(tokens); @@ -916,17 +916,17 @@ void api_watl_parse(WATL_ParseInfo* info, WATL_SliceTok tokens, Opts__watl_parse } Str8 tok_str = watl_tok_str8(tokens, token); - * curr = cache_str8( opts->str_cache, tok_str ); - curr = farena_push(a_nodes, WATL_Node); - * curr = (WATL_Node){0}; - line->len += 1; + * curr = cache_str8( opts->str_cache, tok_str ); + curr = farena_push(a_nodes, WATL_Node); + * curr = (WATL_Node){0}; + line->len += 1; continue; } } #endif DEMO__WATL_PARSE_V1 -WATL_ParseInfo watl__parse(WATL_SliceTok tokens, Opts__watl_parse* opts) { WATL_ParseInfo info; api_watl_parse(& info, tokens, opts); return info; } +WATL_ParseInfo watl__parse(WATL_SliceTok tokens, Opts__watl_parse* opts) { WATL_ParseInfo info; watl_parse_api(& info, tokens, opts); return info; } #ifdef DEMO__WATL_PARSE_V1 int main() @@ -938,17 +938,17 @@ int main() FileOpResult read_res = file_read_contents(lit("demo.str_cache.c"), .backing = fmem_slice(read_mem) ); // This will limit our V1 lex to only 8 megs worth of token tracking on a file. - SliceByte mem_toks = slicemem_alloc(MEGABYTES(8)); + SliceByte mem_toks = slicemem_alloc(MEGABYTES(8)); WATL_LexInfo lex_res = watl_lex(pcast(Str8, read_res.content), .pool_toks = mem_toks); SliceByte mem_cache_strs = slicemem_alloc(MEGABYTES(64)); SliceByte mem_cache_slots = slicemem_alloc(1024 * 1024 * 16 * size_of(Str8Cache_SliceSlot)); SliceByte mem_cache_table = slicemem_alloc(1024 * 16 * size_of(Str8Cache_SliceSlot)); - Str8Cache str_cache = str8cache_init(mem_cache_strs, mem_cache_slots, mem_cache_table); + Str8Cache str_cache = str8cache_init(mem_cache_strs, mem_cache_slots, mem_cache_table); SliceByte mem_parse_nodes = slicemem_alloc(MEGABYTES(4)); SliceByte mem_parse_lines = slicemem_alloc(MEGABYTES(4)); - WATL_ParseInfo parse_res = watl_parse(lex_res.tokens, .backing_nodes = mem_parse_nodes, .backing_lines = mem_parse_lines, .str_cache = & str_cache); + WATL_ParseInfo parse_res = watl_parse(lex_res.tokens, .backing_nodes = mem_parse_nodes, .backing_lines = mem_parse_lines, .str_cache = & str_cache); // unnecessary in this case but if you want to explicitly: slicemem_free(mem_toks); @@ -966,7 +966,7 @@ We'll be utilizing a new construct called a string generator which be tied to al typedef struct Str8Gen Str8Gen; struct Str8Gen { SliceByte backing; // For V1 the backing buffer is fixed size. - char* ptr; + UTF8* ptr; SSIZE len; }; @@ -1021,13 +1021,13 @@ Str8 fmt_vtoken_slice(SliceByte buffer, SliceFmtTokEntry tokens, Str8 fmt_templa slice_assert(tokens); slice_assert(fmt_template); - char* cursor_buffer = buffer.ptr; + UTF8* cursor_buffer = buffer.ptr; SSIZE buffer_remaining = buffer.len; char curr_code = * fmt_template.ptr; - char const* cursor_fmt = fmt_template.ptr; - SSIZE left_fmt = fmt_template.len; + UTF8* cursor_fmt = fmt_template.ptr; + SSIZE left_fmt = fmt_template.len; while (left_fmt && buffer_remaining) { // Forward until we hit the delimiter '<' or the template's contents are exhausted. @@ -1044,8 +1044,8 @@ Str8 fmt_vtoken_slice(SliceByte buffer, SliceFmtTokEntry tokens, Str8 fmt_templa if (curr_code == '<') { - char const* cursor_potential_token = cursor_fmt + 1; - SSIZE potential_token_length = 0; + UTF8* cursor_potential_token = cursor_fmt + 1; + SSIZE potential_token_length = 0; while (* (cursor_potential_token + potential_token_length) != '>') { ++ potential_token_length; @@ -1092,7 +1092,7 @@ Str8 fmt_vtoken_slice(SliceByte buffer, SliceFmtTokEntry tokens, Str8 fmt_templa curr_code = * cursor_fmt; } } - Str8 result = {buffer.ptr, buffer.len - buffer_remaining}; + Str8 result = {buffer.ptr, buffer.len - buffer_remaining}; return result; } @@ -1117,7 +1117,7 @@ Str8 fmt__vtoken(SliceByte backing, Str8 fmt_template, SliceStr8* tokens) ++ table.len; } SliceByte buffer = { .ptr = cast(U8*, a_backing.start) + a_backing.used, .len = a_backing.capacity - a_backing.used }; - Str8 result = fmt_vtoken_slice(buffer, table, fmt_template); + Str8 result = fmt_vtoken_slice(buffer, table, fmt_template); return result; }