From cfa8094260704927661532f9a79aa36cc77c625b Mon Sep 17 00:00:00 2001 From: Abdelrahman Said Date: Wed, 16 Apr 2025 08:06:05 +0100 Subject: [PATCH 1/6] Fix codegen hidden bugs --- codegen/dbl_list/gen_dbl_list.py | 28 ++++++++++++----------- codegen/dbl_list/snippets/list_empty | 2 +- codegen/dbl_list/snippets/list_insert | 9 ++++---- codegen/dbl_list/snippets/list_pop_back | 1 - codegen/dbl_list/snippets/list_pop_front | 1 - codegen/dbl_list/snippets/list_push_back | 3 +-- codegen/dbl_list/snippets/list_push_front | 3 +-- codegen/dbl_list/snippets/list_remove | 7 +++--- codegen/dbl_list/snippets/node_to_list | 4 +--- 9 files changed, 26 insertions(+), 32 deletions(-) diff --git a/codegen/dbl_list/gen_dbl_list.py b/codegen/dbl_list/gen_dbl_list.py index be35489..1b98353 100644 --- a/codegen/dbl_list/gen_dbl_list.py +++ b/codegen/dbl_list/gen_dbl_list.py @@ -21,15 +21,13 @@ from codegen.datatypes import ( @dataclass class DblListData: out_dir: Path - common_includes: list[CInclude] = field(default_factory=list) hdr_includes: list[CInclude] = field(default_factory=list) src_includes: list[CInclude] = field(default_factory=list) - common_decl_types: list[CStruct] = field(default_factory=list) hdr_decl_types: list[CStruct] = field(default_factory=list) src_decl_types: list[CStruct] = field(default_factory=list) -def gen_dbl_list(): +def gen_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}): def __format_func_body(filename: Path, type_string: str): return load_func_body_from_file(filename).format( T=type_string, @@ -37,11 +35,14 @@ def gen_dbl_list(): Tlower=type_string.lower(), ) + common_includes: list[CInclude] = [ + CInclude(header="../../../common/aliases/aliases.h", local=True), + ] + + common_decl_types: list[CStruct] = [] + datatypes: dict[CDataType, DblListData] = { "Str8": DblListData( - common_includes=[ - CInclude(header="../../../common/aliases/aliases.h", local=True), - ], src_includes=[ CInclude(header="./str8.h", local=True), ], @@ -51,6 +52,8 @@ def gen_dbl_list(): out_dir=WAPP_SRC_ROOT / "core/strings/str8/", ), } + datatypes.update(user_datatypes) + snippets_dir = Path(__file__).parent / "snippets" for _type, dbl_list_data in datatypes.items(): @@ -59,7 +62,7 @@ def gen_dbl_list(): node = CStruct( name=f"{type_string}Node", cargs=[ - CArg(name="string", _type=type_string, pointer=CPointer(_type=CPointerType.SINGLE)), + CArg(name="item", _type=type_string, pointer=CPointer(_type=CPointerType.SINGLE)), CArg(name="prev", _type=f"{type_string}Node", pointer=CPointer(_type=CPointerType.SINGLE)), CArg(name="next", _type=f"{type_string}Node", pointer=CPointer(_type=CPointerType.SINGLE)), ], @@ -70,7 +73,6 @@ def gen_dbl_list(): cargs=[ CArg(name="first", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)), CArg(name="last", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)), - CArg(name="total_size", _type=CType.U64), CArg(name="node_count", _type=CType.U64), ], ) @@ -169,7 +171,7 @@ def gen_dbl_list(): header = CHeader( name=f"{type_string.lower()}_list", - decl_types=dbl_list_data.common_decl_types + dbl_list_data.hdr_decl_types, + decl_types=common_decl_types + dbl_list_data.hdr_decl_types, includes=[], types=[node, dl_list], funcs=[ @@ -186,15 +188,15 @@ def gen_dbl_list(): source = CSource( name=header.name, - decl_types=dbl_list_data.common_decl_types + dbl_list_data.src_decl_types, + decl_types=common_decl_types + dbl_list_data.src_decl_types, includes=[CInclude(header, local=True, same_dir=True), CInclude(header="stddef.h")], internal_funcs=[node_to_list_func], funcs=header.funcs ) - if len(dbl_list_data.common_includes) > 0: - header.includes.extend(dbl_list_data.common_includes) - source.includes.extend(dbl_list_data.common_includes) + if len(common_includes) > 0: + header.includes.extend(common_includes) + source.includes.extend(common_includes) if len(dbl_list_data.hdr_includes) > 0: header.includes.extend(dbl_list_data.hdr_includes) diff --git a/codegen/dbl_list/snippets/list_empty b/codegen/dbl_list/snippets/list_empty index c14804f..93380be 100644 --- a/codegen/dbl_list/snippets/list_empty +++ b/codegen/dbl_list/snippets/list_empty @@ -4,5 +4,5 @@ u64 count = list->node_count; for (u64 i = 0; i < count; ++i) {{ - wapp_str8_list_pop_back(list); + wapp_{T}_list_pop_back(list); }} diff --git a/codegen/dbl_list/snippets/list_insert b/codegen/dbl_list/snippets/list_insert index 0b6aa52..88f45b6 100644 --- a/codegen/dbl_list/snippets/list_insert +++ b/codegen/dbl_list/snippets/list_insert @@ -1,23 +1,22 @@ - if (!list || !node || !(node->string)) {{ + if (!list || !node || !(node->item)) {{ return; }} if (index == 0) {{ - wapp_str8_list_push_front(list, node); + wapp_{T}_list_push_front(list, node); return; }} else if (index == list->node_count) {{ - wapp_str8_list_push_back(list, node); + wapp_{T}_list_push_back(list, node); return; }} - {T}Node *dst_node = wapp_str8_list_get(list, index); + {T}Node *dst_node = wapp_{T}_list_get(list, index); if (!dst_node) {{ return; }} {T}List node_list = {Tlower}_node_to_list(node); - list->total_size += node_list.total_size; list->node_count += node_list.node_count; {T}Node *prev = dst_node->prev; diff --git a/codegen/dbl_list/snippets/list_pop_back b/codegen/dbl_list/snippets/list_pop_back index 3ee8a15..67e370a 100644 --- a/codegen/dbl_list/snippets/list_pop_back +++ b/codegen/dbl_list/snippets/list_pop_back @@ -12,7 +12,6 @@ }} --(list->node_count); - list->total_size -= output->string->size; list->last = output->prev; output->prev = output->next = NULL; diff --git a/codegen/dbl_list/snippets/list_pop_front b/codegen/dbl_list/snippets/list_pop_front index caba8c9..97de159 100644 --- a/codegen/dbl_list/snippets/list_pop_front +++ b/codegen/dbl_list/snippets/list_pop_front @@ -12,7 +12,6 @@ }} --(list->node_count); - list->total_size -= output->string->size; list->first = output->next; output->prev = output->next = NULL; diff --git a/codegen/dbl_list/snippets/list_push_back b/codegen/dbl_list/snippets/list_push_back index cc51dac..4d7b004 100644 --- a/codegen/dbl_list/snippets/list_push_back +++ b/codegen/dbl_list/snippets/list_push_back @@ -1,4 +1,4 @@ - if (!list || !node || !(node->string)) {{ + if (!list || !node || !(node->item)) {{ return; }} @@ -9,7 +9,6 @@ return; }} - list->total_size += node_list.total_size; list->node_count += node_list.node_count; {T}Node *last = list->last; diff --git a/codegen/dbl_list/snippets/list_push_front b/codegen/dbl_list/snippets/list_push_front index 8989beb..784f669 100644 --- a/codegen/dbl_list/snippets/list_push_front +++ b/codegen/dbl_list/snippets/list_push_front @@ -1,4 +1,4 @@ - if (!list || !node || !(node->string)) {{ + if (!list || !node || !(node->item)) {{ return; }} @@ -9,7 +9,6 @@ return; }} - list->total_size += node_list.total_size; list->node_count += node_list.node_count; {T}Node *first = list->first; diff --git a/codegen/dbl_list/snippets/list_remove b/codegen/dbl_list/snippets/list_remove index cc213c4..31d0a39 100644 --- a/codegen/dbl_list/snippets/list_remove +++ b/codegen/dbl_list/snippets/list_remove @@ -4,14 +4,14 @@ }} if (index == 0) {{ - output = wapp_str8_list_pop_front(list); + output = wapp_{T}_list_pop_front(list); goto RETURN_{Tupper}_LIST_REMOVE; }} else if (index == list->node_count) {{ - output = wapp_str8_list_pop_back(list); + output = wapp_{T}_list_pop_back(list); goto RETURN_{Tupper}_LIST_REMOVE; }} - output = wapp_str8_list_get(list, index); + output = wapp_{T}_list_get(list, index); if (!output) {{ goto RETURN_{Tupper}_LIST_REMOVE; }} @@ -20,7 +20,6 @@ output->next->prev = output->prev; --(list->node_count); - list->total_size -= output->string->size; output->prev = output->next = NULL; diff --git a/codegen/dbl_list/snippets/node_to_list b/codegen/dbl_list/snippets/node_to_list index 2c52609..6f88b81 100644 --- a/codegen/dbl_list/snippets/node_to_list +++ b/codegen/dbl_list/snippets/node_to_list @@ -1,13 +1,11 @@ - {T}List output = {{.first = node, .last = node, .total_size = node->string->size, .node_count = 1}}; + {T}List output = {{.first = node, .last = node, .total_size = node->item->size, .node_count = 1}}; while (output.first->prev != NULL) {{ - output.total_size += output.first->prev->string->size; output.first = output.first->prev; ++(output.node_count); }} while (output.last->next != NULL) {{ - output.total_size += output.last->next->string->size; output.last = output.last->next; ++(output.node_count); }} From 63acdd13366526738313ee6f61e3be8c7d7ed2a1 Mon Sep 17 00:00:00 2001 From: Abdelrahman Said Date: Wed, 16 Apr 2025 08:13:31 +0100 Subject: [PATCH 2/6] Fix codegen bugs --- codegen/datatypes.py | 2 +- codegen/dbl_list/snippets/list_empty | 2 +- codegen/dbl_list/snippets/list_insert | 6 +++--- codegen/dbl_list/snippets/list_remove | 6 +++--- codegen/dbl_list/snippets/node_to_list | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/codegen/datatypes.py b/codegen/datatypes.py index fab1b9d..58e5baa 100644 --- a/codegen/datatypes.py +++ b/codegen/datatypes.py @@ -162,7 +162,7 @@ class CFunc: return f"{str(self)};\n" def define(self) -> str: - return f"{str(self)} {{\n{self.body}\n}}\n\n" + return f"{str(self)} {{\n{self.body}}}\n\n" @dataclass diff --git a/codegen/dbl_list/snippets/list_empty b/codegen/dbl_list/snippets/list_empty index 93380be..a5e2c4a 100644 --- a/codegen/dbl_list/snippets/list_empty +++ b/codegen/dbl_list/snippets/list_empty @@ -4,5 +4,5 @@ u64 count = list->node_count; for (u64 i = 0; i < count; ++i) {{ - wapp_{T}_list_pop_back(list); + wapp_{Tlower}_list_pop_back(list); }} diff --git a/codegen/dbl_list/snippets/list_insert b/codegen/dbl_list/snippets/list_insert index 88f45b6..e8eb294 100644 --- a/codegen/dbl_list/snippets/list_insert +++ b/codegen/dbl_list/snippets/list_insert @@ -3,14 +3,14 @@ }} if (index == 0) {{ - wapp_{T}_list_push_front(list, node); + wapp_{Tlower}_list_push_front(list, node); return; }} else if (index == list->node_count) {{ - wapp_{T}_list_push_back(list, node); + wapp_{Tlower}_list_push_back(list, node); return; }} - {T}Node *dst_node = wapp_{T}_list_get(list, index); + {T}Node *dst_node = wapp_{Tlower}_list_get(list, index); if (!dst_node) {{ return; }} diff --git a/codegen/dbl_list/snippets/list_remove b/codegen/dbl_list/snippets/list_remove index 31d0a39..90095b5 100644 --- a/codegen/dbl_list/snippets/list_remove +++ b/codegen/dbl_list/snippets/list_remove @@ -4,14 +4,14 @@ }} if (index == 0) {{ - output = wapp_{T}_list_pop_front(list); + output = wapp_{Tlower}_list_pop_front(list); goto RETURN_{Tupper}_LIST_REMOVE; }} else if (index == list->node_count) {{ - output = wapp_{T}_list_pop_back(list); + output = wapp_{Tlower}_list_pop_back(list); goto RETURN_{Tupper}_LIST_REMOVE; }} - output = wapp_{T}_list_get(list, index); + output = wapp_{Tlower}_list_get(list, index); if (!output) {{ goto RETURN_{Tupper}_LIST_REMOVE; }} diff --git a/codegen/dbl_list/snippets/node_to_list b/codegen/dbl_list/snippets/node_to_list index 6f88b81..b11a634 100644 --- a/codegen/dbl_list/snippets/node_to_list +++ b/codegen/dbl_list/snippets/node_to_list @@ -1,4 +1,4 @@ - {T}List output = {{.first = node, .last = node, .total_size = node->item->size, .node_count = 1}}; + {T}List output = {{.first = node, .last = node, .node_count = 1}}; while (output.first->prev != NULL) {{ output.first = output.first->prev; From 2017f6de79173c33cf6a0228d2423ff3153a08d6 Mon Sep 17 00:00:00 2001 From: Abdelrahman Said Date: Wed, 16 Apr 2025 08:14:02 +0100 Subject: [PATCH 3/6] Start updating code for new Str8List --- src/core/strings/str8/str8.c | 4 ++++ src/core/strings/str8/str8.h | 5 +++-- src/core/strings/str8/str8_list.c | 25 ++++--------------------- src/core/strings/str8/str8_list.h | 3 +-- 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/core/strings/str8/str8.c b/src/core/strings/str8/str8.c index 59d82e3..b86e2ac 100644 --- a/src/core/strings/str8/str8.c +++ b/src/core/strings/str8/str8.c @@ -433,3 +433,7 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d return output; } + +u64 wapp_str8_list_total_size(const Str8List *list) { + +} diff --git a/src/core/strings/str8/str8.h b/src/core/strings/str8/str8.h index 894e4c2..725b65d 100644 --- a/src/core/strings/str8/str8.h +++ b/src/core/strings/str8/str8.h @@ -91,8 +91,9 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8R /** * Str8 list utilities */ -#define wapp_str8_node_from_cstr(STRING) ((Str8Node){.string = &wapp_str8_lit(STRING)}) -#define wapp_str8_node_from_str8(STRING) ((Str8Node){.string = &(STRING)}) +#define wapp_str8_node_from_cstr(STRING) ((Str8Node){.item = &wapp_str8_lit(STRING)}) +#define wapp_str8_node_from_str8(STRING) ((Str8Node){.item = &(STRING)}) +u64 wapp_str8_list_total_size(const Str8List *list); #ifdef __cplusplus END_C_LINKAGE diff --git a/src/core/strings/str8/str8_list.c b/src/core/strings/str8/str8_list.c index a3cebbe..98f9f94 100644 --- a/src/core/strings/str8/str8_list.c +++ b/src/core/strings/str8/str8_list.c @@ -23,11 +23,10 @@ Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) { output = current; return output; - } void wapp_str8_list_push_front(Str8List *list, Str8Node *node) { - if (!list || !node || !(node->string)) { + if (!list || !node || !(node->item)) { return; } @@ -38,7 +37,6 @@ void wapp_str8_list_push_front(Str8List *list, Str8Node *node) { return; } - list->total_size += node_list.total_size; list->node_count += node_list.node_count; Str8Node *first = list->first; @@ -48,11 +46,10 @@ void wapp_str8_list_push_front(Str8List *list, Str8Node *node) { list->first = node_list.first; node_list.last->next = first; - } void wapp_str8_list_push_back(Str8List *list, Str8Node *node) { - if (!list || !node || !(node->string)) { + if (!list || !node || !(node->item)) { return; } @@ -63,7 +60,6 @@ void wapp_str8_list_push_back(Str8List *list, Str8Node *node) { return; } - list->total_size += node_list.total_size; list->node_count += node_list.node_count; Str8Node *last = list->last; @@ -73,11 +69,10 @@ void wapp_str8_list_push_back(Str8List *list, Str8Node *node) { list->last = node_list.last; node_list.first->prev = last; - } void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) { - if (!list || !node || !(node->string)) { + if (!list || !node || !(node->item)) { return; } @@ -96,7 +91,6 @@ void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) { Str8List node_list = str8_node_to_list(node); - list->total_size += node_list.total_size; list->node_count += node_list.node_count; Str8Node *prev = dst_node->prev; @@ -106,7 +100,6 @@ void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) { node_list.first->prev = prev; node_list.last->next = dst_node; - } Str8Node *wapp_str8_list_pop_front(Str8List *list) { @@ -124,14 +117,12 @@ Str8Node *wapp_str8_list_pop_front(Str8List *list) { } --(list->node_count); - list->total_size -= output->string->size; list->first = output->next; output->prev = output->next = NULL; RETURN_STR8_LIST_POP_FRONT: return output; - } Str8Node *wapp_str8_list_pop_back(Str8List *list) { @@ -149,14 +140,12 @@ Str8Node *wapp_str8_list_pop_back(Str8List *list) { } --(list->node_count); - list->total_size -= output->string->size; list->last = output->prev; output->prev = output->next = NULL; RETURN_STR8_LIST_POP_BACK: return output; - } Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) { @@ -182,13 +171,11 @@ Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) { output->next->prev = output->prev; --(list->node_count); - list->total_size -= output->string->size; output->prev = output->next = NULL; RETURN_STR8_LIST_REMOVE: return output; - } void wapp_str8_list_empty(Str8List *list) { @@ -200,25 +187,21 @@ void wapp_str8_list_empty(Str8List *list) { for (u64 i = 0; i < count; ++i) { wapp_str8_list_pop_back(list); } - } internal Str8List str8_node_to_list(Str8Node *node) { - Str8List output = {.first = node, .last = node, .total_size = node->string->size, .node_count = 1}; + Str8List output = {.first = node, .last = node, .node_count = 1}; while (output.first->prev != NULL) { - output.total_size += output.first->prev->string->size; output.first = output.first->prev; ++(output.node_count); } while (output.last->next != NULL) { - output.total_size += output.last->next->string->size; output.last = output.last->next; ++(output.node_count); } return output; - } diff --git a/src/core/strings/str8/str8_list.h b/src/core/strings/str8/str8_list.h index 2476871..529c5c0 100644 --- a/src/core/strings/str8/str8_list.h +++ b/src/core/strings/str8/str8_list.h @@ -15,7 +15,7 @@ typedef struct str8 Str8; typedef struct Str8Node Str8Node; struct Str8Node { - Str8 *string; + Str8 *item; Str8Node *prev; Str8Node *next; }; @@ -24,7 +24,6 @@ typedef struct Str8List Str8List; struct Str8List { Str8Node *first; Str8Node *last; - u64 total_size; u64 node_count; }; From aa04fab6ea5b7569f220ffd0d540fa2586695155 Mon Sep 17 00:00:00 2001 From: Abdelrahman Said Date: Wed, 16 Apr 2025 10:05:42 +0100 Subject: [PATCH 4/6] Update codegen --- codegen/__main__.py | 12 ++- codegen/datatypes.py | 2 +- codegen/utils.py | 2 +- src/core/os/cpath/cpath.c | 12 +-- src/core/strings/str8/str8.c | 26 +++++-- src/core/strings/str8/str8_list.c | 18 ++--- tests/str8/test_str8.c | 24 +++--- tests/str8/test_str8_list.c | 124 +++++++++++++++--------------- 8 files changed, 119 insertions(+), 101 deletions(-) diff --git a/codegen/__main__.py b/codegen/__main__.py index 9135022..ee75b61 100644 --- a/codegen/__main__.py +++ b/codegen/__main__.py @@ -1,8 +1,16 @@ -from codegen.dbl_list.gen_dbl_list import gen_dbl_list +from pathlib import Path +from codegen.datatypes import CDataType +from codegen.dbl_list.gen_dbl_list import DblListData, gen_dbl_list def main(): - gen_dbl_list() + datatypes: dict[CDataType, DblListData] = { + "int": DblListData( + out_dir=Path("/Users/abdelrahman/dev/personal/wizapp-stdlib"), + ), + } + + gen_dbl_list(datatypes) if __name__ == "__main__": diff --git a/codegen/datatypes.py b/codegen/datatypes.py index 58e5baa..fab1b9d 100644 --- a/codegen/datatypes.py +++ b/codegen/datatypes.py @@ -162,7 +162,7 @@ class CFunc: return f"{str(self)};\n" def define(self) -> str: - return f"{str(self)} {{\n{self.body}}}\n\n" + return f"{str(self)} {{\n{self.body}\n}}\n\n" @dataclass diff --git a/codegen/utils.py b/codegen/utils.py index 5247512..47b6b16 100644 --- a/codegen/utils.py +++ b/codegen/utils.py @@ -3,4 +3,4 @@ from pathlib import Path def load_func_body_from_file(filename: Path) -> str: with open(filename, "r") as infile: - return infile.read() + return infile.read().strip() diff --git a/src/core/os/cpath/cpath.c b/src/core/os/cpath/cpath.c index e234448..69414ca 100644 --- a/src/core/os/cpath/cpath.c +++ b/src/core/os/cpath/cpath.c @@ -21,14 +21,14 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) { Str8 separator = wapp_str8_buf(4); wapp_str8_push_back(&separator, PATH_SEP); - u64 required_capacity = parts->node_count * separator.size + parts->total_size; + u64 required_capacity = parts->node_count * separator.size + wapp_str8_list_total_size(parts); if (dst->capacity < required_capacity) { return CPATH_JOIN_INSUFFICIENT_DST_CAPACITY; } // Handle first node const Str8Node *first_node = wapp_str8_list_get(parts, 0); - wapp_str8_copy_str8_capped(dst, first_node->string); + wapp_str8_copy_str8_capped(dst, first_node->item); // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings @@ -37,13 +37,13 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) { bool running = true; while (running && node->next) { node = node->next; - if (node->string->size == 0) { + if (node->item->size == 0) { continue; } if (dst->size > 0) { char dst_last = wapp_str8_get(dst, dst->size - 1); - char node_start = wapp_str8_get(node->string, 0); + char node_start = wapp_str8_get(node->item, 0); bool add_path_sep = dst_last != PATH_SEP && node_start != PATH_SEP; if (add_path_sep) { @@ -51,7 +51,7 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) { } } - wapp_str8_concat_capped(dst, node->string); + wapp_str8_concat_capped(dst, node->item); ++node_index; running = node_index < parts->node_count; @@ -108,7 +108,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) { } u64 alignment = sizeof(void *) * 2; - u64 alloc_size = parts->total_size + parts->node_count * separator.size; + u64 alloc_size = wapp_str8_list_total_size(parts) + parts->node_count * separator.size; u64 modulo = alloc_size & (alignment - 1); alloc_size += alignment - modulo; diff --git a/src/core/strings/str8/str8.c b/src/core/strings/str8/str8.c index b86e2ac..fb6900b 100644 --- a/src/core/strings/str8/str8.c +++ b/src/core/strings/str8/str8.c @@ -311,7 +311,7 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8 Str8 *full = wapp_str8_alloc_str8(allocator, str); Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node)); if (node) { - node->string = full; + node->item = full; wapp_str8_list_push_back(output, node); } @@ -332,7 +332,7 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8 before_str = wapp_str8_alloc_substr(allocator, str, start, start + end); Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node)); if (node) { - node->string = before_str; + node->item = before_str; wapp_str8_list_push_back(output, node); } @@ -347,7 +347,7 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8 rest = wapp_str8_alloc_substr(allocator, str, start, str->size); Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node)); if (node) { - node->string = rest; + node->item = rest; wapp_str8_list_push_back(output, node); } @@ -366,7 +366,7 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str Str8 *full = wapp_str8_alloc_str8(allocator, str); Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node)); if (node) { - node->string = full; + node->item = full; wapp_str8_list_push_back(output, node); } @@ -386,7 +386,7 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size); Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node)); if (node) { - node->string = after_str; + node->item = after_str; wapp_str8_list_push_front(output, node); } @@ -399,7 +399,7 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size); Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node)); if (node) { - node->string = rest; + node->item = rest; wapp_str8_list_push_front(output, node); } @@ -412,7 +412,7 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d return NULL; } - u64 capacity = list->total_size + (delimiter->size * (list->node_count - 1)); + u64 capacity = wapp_str8_list_total_size(list) + (delimiter->size * (list->node_count - 1)); Str8 *output = wapp_str8_alloc_buf(allocator, capacity * 2); // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of @@ -422,7 +422,7 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d bool running = true; while (running) { node = wapp_str8_list_get(list, node_index); - wapp_str8_concat_capped(output, node->string); + wapp_str8_concat_capped(output, node->item); if (node_index + 1 < list->node_count) { wapp_str8_concat_capped(output, delimiter); } @@ -435,5 +435,15 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d } u64 wapp_str8_list_total_size(const Str8List *list) { + if (!list) { + return 0; + } + u64 output = 0; + for (u64 i = 0; i < list->node_count; ++i) { + Str8Node *node = wapp_str8_list_get(list, i); + output += node->item->size; + } + + return output; } diff --git a/src/core/strings/str8/str8_list.c b/src/core/strings/str8/str8_list.c index 98f9f94..a648311 100644 --- a/src/core/strings/str8/str8_list.c +++ b/src/core/strings/str8/str8_list.c @@ -10,7 +10,7 @@ internal Str8List str8_node_to_list(Str8Node *node); Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) { - if (index >= list->node_count) { +if (index >= list->node_count) { return NULL; } @@ -26,7 +26,7 @@ Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) { } void wapp_str8_list_push_front(Str8List *list, Str8Node *node) { - if (!list || !node || !(node->item)) { +if (!list || !node || !(node->item)) { return; } @@ -49,7 +49,7 @@ void wapp_str8_list_push_front(Str8List *list, Str8Node *node) { } void wapp_str8_list_push_back(Str8List *list, Str8Node *node) { - if (!list || !node || !(node->item)) { +if (!list || !node || !(node->item)) { return; } @@ -72,7 +72,7 @@ void wapp_str8_list_push_back(Str8List *list, Str8Node *node) { } void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) { - if (!list || !node || !(node->item)) { +if (!list || !node || !(node->item)) { return; } @@ -103,7 +103,7 @@ void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) { } Str8Node *wapp_str8_list_pop_front(Str8List *list) { - Str8Node *output = NULL; +Str8Node *output = NULL; if (!list || list->node_count == 0) { goto RETURN_STR8_LIST_POP_FRONT; @@ -126,7 +126,7 @@ RETURN_STR8_LIST_POP_FRONT: } Str8Node *wapp_str8_list_pop_back(Str8List *list) { - Str8Node *output = NULL; +Str8Node *output = NULL; if (!list || list->node_count == 0) { goto RETURN_STR8_LIST_POP_BACK; @@ -149,7 +149,7 @@ RETURN_STR8_LIST_POP_BACK: } Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) { - Str8Node *output = NULL; +Str8Node *output = NULL; if (!list) { goto RETURN_STR8_LIST_REMOVE; } @@ -179,7 +179,7 @@ RETURN_STR8_LIST_REMOVE: } void wapp_str8_list_empty(Str8List *list) { - if (!list) { +if (!list) { return; } @@ -190,7 +190,7 @@ void wapp_str8_list_empty(Str8List *list) { } internal Str8List str8_node_to_list(Str8Node *node) { - Str8List output = {.first = node, .last = node, .node_count = 1}; +Str8List output = {.first = node, .last = node, .node_count = 1}; while (output.first->prev != NULL) { output.first = output.first->prev; diff --git a/tests/str8/test_str8.c b/tests/str8/test_str8.c index adf41af..053c1da 100644 --- a/tests/str8/test_str8.c +++ b/tests/str8/test_str8.c @@ -438,14 +438,14 @@ TestFuncResult test_str8_split(void) { u64 count2 = ARRLEN(splits2); bool running2 = true; - result = list1->node_count == count1 && list1->total_size == str.size - 3; - result = result && list2->node_count == count2 && list2->total_size == str.size - 4; + result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3; + result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4; // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings while (running1) { Str8Node *node = wapp_str8_list_get(list1, index1); - result = result && wapp_str8_equal(node->string, &(splits1[index1])); + result = result && wapp_str8_equal(node->item, &(splits1[index1])); ++index1; running1 = index1 < count1; @@ -455,7 +455,7 @@ TestFuncResult test_str8_split(void) { // MSVC Spectre mitigation warnings while (running2) { Str8Node *node = wapp_str8_list_get(list2, index2); - result = result && wapp_str8_equal(node->string, &(splits2[index2])); + result = result && wapp_str8_equal(node->item, &(splits2[index2])); ++index2; running2 = index2 < count2; @@ -484,13 +484,13 @@ TestFuncResult test_str8_split_with_max(void) { u64 count = ARRLEN(splits); bool running = true; - result = list->node_count == count && list->total_size == str.size - 2; + result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2; // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings while (running) { Str8Node *node = wapp_str8_list_get(list, index); - result = result && wapp_str8_equal(node->string, &(splits[index])); + result = result && wapp_str8_equal(node->item, &(splits[index])); ++index; running = index < count; @@ -530,14 +530,14 @@ TestFuncResult test_str8_rsplit(void) { u64 count2 = ARRLEN(splits2); bool running2 = true; - result = list1->node_count == count1 && list1->total_size == str.size - 3; - result = result && list2->node_count == count2 && list2->total_size == str.size - 4; + result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3; + result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4; // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings while (running1) { Str8Node *node = wapp_str8_list_get(list1, index1); - result = result && wapp_str8_equal(node->string, &(splits1[index1])); + result = result && wapp_str8_equal(node->item, &(splits1[index1])); ++index1; running1 = index1 < count1; @@ -547,7 +547,7 @@ TestFuncResult test_str8_rsplit(void) { // MSVC Spectre mitigation warnings while (running2) { Str8Node *node = wapp_str8_list_get(list2, index2); - result = result && wapp_str8_equal(node->string, &(splits2[index2])); + result = result && wapp_str8_equal(node->item, &(splits2[index2])); ++index2; running2 = index2 < count2; @@ -576,13 +576,13 @@ TestFuncResult test_str8_rsplit_with_max(void) { u64 count = ARRLEN(splits); bool running = true; - result = list->node_count == count && list->total_size == str.size - 2; + result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2; // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings while (running) { Str8Node *node = wapp_str8_list_get(list, index); - result = result && wapp_str8_equal(node->string, &(splits[index])); + result = result && wapp_str8_equal(node->item, &(splits[index])); ++index; running = index < count; diff --git a/tests/str8/test_str8_list.c b/tests/str8/test_str8_list.c index b11ded9..d47e55c 100644 --- a/tests/str8/test_str8_list.c +++ b/tests/str8/test_str8_list.c @@ -11,11 +11,11 @@ TestFuncResult test_str8_list_get(void) { Str8 s5 = wapp_str8_lit("5"); Str8List list = {0}; - Str8Node n1 = { .string = &s1 }; - Str8Node n2 = { .string = &s2 }; - Str8Node n3 = { .string = &s3 }; - Str8Node n4 = { .string = &s4 }; - Str8Node n5 = { .string = &s5 }; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + Str8Node n3 = { .item = &s3 }; + Str8Node n4 = { .item = &s4 }; + Str8Node n5 = { .item = &s5 }; wapp_str8_list_push_back(&list, &n1); wapp_str8_list_push_back(&list, &n2); @@ -24,19 +24,19 @@ TestFuncResult test_str8_list_get(void) { wapp_str8_list_push_back(&list, &n5); Str8Node *node = wapp_str8_list_get(&list, 0); - result = node->string == &s1 && wapp_str8_equal(node->string, &s1); + result = node->item == &s1 && wapp_str8_equal(node->item, &s1); node = wapp_str8_list_get(&list, 1); - result = result && node->string == &s2 && wapp_str8_equal(node->string, &s2); + result = result && node->item == &s2 && wapp_str8_equal(node->item, &s2); node = wapp_str8_list_get(&list, 2); - result = result && node->string == &s3 && wapp_str8_equal(node->string, &s3); + result = result && node->item == &s3 && wapp_str8_equal(node->item, &s3); node = wapp_str8_list_get(&list, 3); - result = result && node->string == &s4 && wapp_str8_equal(node->string, &s4); + result = result && node->item == &s4 && wapp_str8_equal(node->item, &s4); node = wapp_str8_list_get(&list, 4); - result = result && node->string == &s5 && wapp_str8_equal(node->string, &s5); + result = result && node->item == &s5 && wapp_str8_equal(node->item, &s5); return wapp_tester_result(result); } @@ -49,18 +49,18 @@ TestFuncResult test_str8_list_push_front(void) { Str8 s3 = wapp_str8_lit("3"); Str8List list = {0}; - Str8Node n1 = { .string = &s1 }; - Str8Node n2 = { .string = &s2 }; - Str8Node n3 = { .string = &s3 }; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + Str8Node n3 = { .item = &s3 }; wapp_str8_list_push_front(&list, &n1); - result = list.first == list.last && list.first == &n1 && list.first->string == &s1 && list.total_size == 1 && list.node_count == 1; + result = list.first == list.last && list.first == &n1 && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; wapp_str8_list_push_front(&list, &n2); - result = result && list.first == &n2 && list.first->string == &s2 && list.total_size == 2 && list.node_count == 2; + result = result && list.first == &n2 && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; wapp_str8_list_push_front(&list, &n3); - result = result && list.first == &n3 && list.first->string == &s3 && list.total_size == 3 && list.node_count == 3; + result = result && list.first == &n3 && list.first->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; return wapp_tester_result(result); } @@ -73,18 +73,18 @@ TestFuncResult test_str8_list_push_back(void) { Str8 s3 = wapp_str8_lit("3"); Str8List list = {0}; - Str8Node n1 = { .string = &s1 }; - Str8Node n2 = { .string = &s2 }; - Str8Node n3 = { .string = &s3 }; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + Str8Node n3 = { .item = &s3 }; wapp_str8_list_push_back(&list, &n1); - result = list.first == list.last && list.last == &n1 && list.last->string == &s1 && list.total_size == 1 && list.node_count == 1; + result = list.first == list.last && list.last == &n1 && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; wapp_str8_list_push_back(&list, &n2); - result = result && list.last == &n2 && list.last->string == &s2 && list.total_size == 2 && list.node_count == 2; + result = result && list.last == &n2 && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; wapp_str8_list_push_back(&list, &n3); - result = result && list.last == &n3 && list.last->string == &s3 && list.total_size == 3 && list.node_count == 3; + result = result && list.last == &n3 && list.last->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; return wapp_tester_result(result); } @@ -101,13 +101,13 @@ TestFuncResult test_str8_list_insert(void) { Str8 s7 = wapp_str8_lit("7"); Str8List list = {0}; - Str8Node n1 = { .string = &s1 }; - Str8Node n2 = { .string = &s2 }; - Str8Node n3 = { .string = &s3 }; - Str8Node n4 = { .string = &s4 }; - Str8Node n5 = { .string = &s5 }; - Str8Node n6 = { .string = &s6 }; - Str8Node n7 = { .string = &s7 }; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + Str8Node n3 = { .item = &s3 }; + Str8Node n4 = { .item = &s4 }; + Str8Node n5 = { .item = &s5 }; + Str8Node n6 = { .item = &s6 }; + Str8Node n7 = { .item = &s7 }; wapp_str8_list_push_back(&list, &n1); wapp_str8_list_push_back(&list, &n2); @@ -118,10 +118,10 @@ TestFuncResult test_str8_list_insert(void) { Str8Node *node; wapp_str8_list_insert(&list, &n6, 2); node = wapp_str8_list_get(&list, 2); - result = node != NULL && node->string == &s6 && list.total_size == 6 && list.node_count == 6; + result = node != NULL && node->item == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6; wapp_str8_list_insert(&list, &n7, 5); node = wapp_str8_list_get(&list, 5); - result = result && node != NULL && node->string == &s7 && list.total_size == 7 && list.node_count == 7; + result = result && node != NULL && node->item == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7; return wapp_tester_result(result); } @@ -136,11 +136,11 @@ TestFuncResult test_str8_list_pop_front(void) { Str8 s5 = wapp_str8_lit("5"); Str8List list = {0}; - Str8Node n1 = { .string = &s1 }; - Str8Node n2 = { .string = &s2 }; - Str8Node n3 = { .string = &s3 }; - Str8Node n4 = { .string = &s4 }; - Str8Node n5 = { .string = &s5 }; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + Str8Node n3 = { .item = &s3 }; + Str8Node n4 = { .item = &s4 }; + Str8Node n5 = { .item = &s5 }; wapp_str8_list_push_back(&list, &n1); wapp_str8_list_push_back(&list, &n2); @@ -149,19 +149,19 @@ TestFuncResult test_str8_list_pop_front(void) { wapp_str8_list_push_back(&list, &n5); Str8Node *node = wapp_str8_list_pop_front(&list); - result = node == &n1 && node->string == &s1 && wapp_str8_equal(node->string, &s1) && list.total_size == 4 && list.node_count == 4; + result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; node = wapp_str8_list_pop_front(&list); - result = result && node == &n2 && node->string == &s2 && wapp_str8_equal(node->string, &s2) && list.total_size == 3 && list.node_count == 3; + result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; node = wapp_str8_list_pop_front(&list); - result = result && node == &n3 && node->string == &s3 && wapp_str8_equal(node->string, &s3) && list.total_size == 2 && list.node_count == 2; + result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; node = wapp_str8_list_pop_front(&list); - result = result && node == &n4 && node->string == &s4 && wapp_str8_equal(node->string, &s4) && list.total_size == 1 && list.node_count == 1; + result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; node = wapp_str8_list_pop_front(&list); - result = result && node == &n5 && node->string == &s5 && wapp_str8_equal(node->string, &s5) && list.total_size == 0 && list.node_count == 0; + result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; return wapp_tester_result(result); } @@ -176,11 +176,11 @@ TestFuncResult test_str8_list_pop_back(void) { Str8 s5 = wapp_str8_lit("5"); Str8List list = {0}; - Str8Node n1 = { .string = &s1 }; - Str8Node n2 = { .string = &s2 }; - Str8Node n3 = { .string = &s3 }; - Str8Node n4 = { .string = &s4 }; - Str8Node n5 = { .string = &s5 }; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + Str8Node n3 = { .item = &s3 }; + Str8Node n4 = { .item = &s4 }; + Str8Node n5 = { .item = &s5 }; wapp_str8_list_push_front(&list, &n1); wapp_str8_list_push_front(&list, &n2); @@ -189,19 +189,19 @@ TestFuncResult test_str8_list_pop_back(void) { wapp_str8_list_push_front(&list, &n5); Str8Node *node = wapp_str8_list_pop_back(&list); - result = node == &n1 && node->string == &s1 && wapp_str8_equal(node->string, &s1) && list.total_size == 4 && list.node_count == 4; + result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; node = wapp_str8_list_pop_back(&list); - result = result && node == &n2 && node->string == &s2 && wapp_str8_equal(node->string, &s2) && list.total_size == 3 && list.node_count == 3; + result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; node = wapp_str8_list_pop_back(&list); - result = result && node == &n3 && node->string == &s3 && wapp_str8_equal(node->string, &s3) && list.total_size == 2 && list.node_count == 2; + result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; node = wapp_str8_list_pop_back(&list); - result = result && node == &n4 && node->string == &s4 && wapp_str8_equal(node->string, &s4) && list.total_size == 1 && list.node_count == 1; + result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; node = wapp_str8_list_pop_back(&list); - result = result && node == &n5 && node->string == &s5 && wapp_str8_equal(node->string, &s5) && list.total_size == 0 && list.node_count == 0; + result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; return wapp_tester_result(result); } @@ -216,11 +216,11 @@ TestFuncResult test_str8_list_remove(void) { Str8 s5 = wapp_str8_lit("5"); Str8List list = {0}; - Str8Node n1 = { .string = &s1 }; - Str8Node n2 = { .string = &s2 }; - Str8Node n3 = { .string = &s3 }; - Str8Node n4 = { .string = &s4 }; - Str8Node n5 = { .string = &s5 }; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + Str8Node n3 = { .item = &s3 }; + Str8Node n4 = { .item = &s4 }; + Str8Node n5 = { .item = &s5 }; wapp_str8_list_push_back(&list, &n1); wapp_str8_list_push_back(&list, &n2); @@ -229,19 +229,19 @@ TestFuncResult test_str8_list_remove(void) { wapp_str8_list_push_back(&list, &n5); Str8Node *node = wapp_str8_list_remove(&list, 0); - result = node == &n1 && node->string == &s1 && wapp_str8_equal(node->string, &s1) && list.total_size == 4 && list.node_count == 4; + result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; node = wapp_str8_list_remove(&list, 0); - result = result && node == &n2 && node->string == &s2 && wapp_str8_equal(node->string, &s2) && list.total_size == 3 && list.node_count == 3; + result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; node = wapp_str8_list_remove(&list, 0); - result = result && node == &n3 && node->string == &s3 && wapp_str8_equal(node->string, &s3) && list.total_size == 2 && list.node_count == 2; + result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; node = wapp_str8_list_remove(&list, 0); - result = result && node == &n4 && node->string == &s4 && wapp_str8_equal(node->string, &s4) && list.total_size == 1 && list.node_count == 1; + result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; node = wapp_str8_list_remove(&list, 0); - result = result && node == &n5 && node->string == &s5 && wapp_str8_equal(node->string, &s5) && list.total_size == 0 && list.node_count == 0; + result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; return wapp_tester_result(result); } @@ -257,7 +257,7 @@ TestFuncResult test_str8_list_empty(void) { wapp_str8_list_empty(&list); - result = list.first == NULL && list.last == NULL && list.node_count == 0 && list.total_size == 0; + result = list.first == NULL && list.last == NULL && list.node_count == 0 && wapp_str8_list_total_size(&list) == 0; return wapp_tester_result(result); } From 3c32b247c0efbaacd56720b7c57a3bea0f3954d6 Mon Sep 17 00:00:00 2001 From: Abdelrahman Said Date: Thu, 17 Apr 2025 09:03:30 +0100 Subject: [PATCH 5/6] Upgrade codegen --- codegen/__main__.py | 15 ++++---- codegen/constants.py | 2 +- .../{gen_dbl_list.py => make_dbl_list.py} | 38 +++++++++++++------ codegen/dbl_list/snippets/list_get | 4 +- codegen/dbl_list/snippets/list_insert | 6 +-- codegen/dbl_list/snippets/list_node | 1 + codegen/dbl_list/snippets/list_pop_back | 4 +- codegen/dbl_list/snippets/list_pop_front | 4 +- codegen/dbl_list/snippets/list_push_back | 4 +- codegen/dbl_list/snippets/list_push_front | 4 +- codegen/dbl_list/snippets/list_remove | 2 +- codegen/dbl_list/snippets/node_to_list | 2 +- codegen/utils.py | 2 +- src/core/strings/str8/str8_list.c | 23 ++++++----- src/core/strings/str8/str8_list.h | 1 + 15 files changed, 66 insertions(+), 46 deletions(-) rename codegen/dbl_list/{gen_dbl_list.py => make_dbl_list.py} (84%) create mode 100644 codegen/dbl_list/snippets/list_node diff --git a/codegen/__main__.py b/codegen/__main__.py index ee75b61..b03bdc9 100644 --- a/codegen/__main__.py +++ b/codegen/__main__.py @@ -1,16 +1,15 @@ -from pathlib import Path from codegen.datatypes import CDataType -from codegen.dbl_list.gen_dbl_list import DblListData, gen_dbl_list +from codegen.dbl_list.make_dbl_list import DblListData, make_dbl_list def main(): - datatypes: dict[CDataType, DblListData] = { - "int": DblListData( - out_dir=Path("/Users/abdelrahman/dev/personal/wizapp-stdlib"), - ), - } + gen_dbl_list() - gen_dbl_list(datatypes) + +def gen_dbl_list(): + datatypes: dict[CDataType, DblListData] = {} + + make_dbl_list(datatypes) if __name__ == "__main__": diff --git a/codegen/constants.py b/codegen/constants.py index d092b2c..ebad100 100644 --- a/codegen/constants.py +++ b/codegen/constants.py @@ -1,5 +1,5 @@ from pathlib import Path -PACKAGE_DIR = Path(__file__).parent +PACKAGE_DIR = Path(__file__).parent.resolve() WAPP_SRC_ROOT = PACKAGE_DIR.parent / "src" diff --git a/codegen/dbl_list/gen_dbl_list.py b/codegen/dbl_list/make_dbl_list.py similarity index 84% rename from codegen/dbl_list/gen_dbl_list.py rename to codegen/dbl_list/make_dbl_list.py index 1b98353..f979e2c 100644 --- a/codegen/dbl_list/gen_dbl_list.py +++ b/codegen/dbl_list/make_dbl_list.py @@ -27,29 +27,28 @@ class DblListData: src_decl_types: list[CStruct] = field(default_factory=list) -def gen_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}): +def make_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}): def __format_func_body(filename: Path, type_string: str): return load_func_body_from_file(filename).format( T=type_string, + Ttitle=type_string.title(), Tupper=type_string.upper(), Tlower=type_string.lower(), ) - common_includes: list[CInclude] = [ - CInclude(header="../../../common/aliases/aliases.h", local=True), + common_local_include_files = [ + (WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h") ] + common_includes: list[CInclude] = [] common_decl_types: list[CStruct] = [] datatypes: dict[CDataType, DblListData] = { "Str8": DblListData( - src_includes=[ - CInclude(header="./str8.h", local=True), - ], hdr_decl_types=[ CStruct(name="str8", cargs=[], typedef_name="Str8"), ], - out_dir=WAPP_SRC_ROOT / "core/strings/str8/", + out_dir=WAPP_SRC_ROOT / "core" / "strings" / "str8", ), } datatypes.update(user_datatypes) @@ -60,16 +59,18 @@ def gen_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}): type_string = get_datatype_string(_type) node = CStruct( - name=f"{type_string}Node", + name=f"{type_string.title()}Node", cargs=[ CArg(name="item", _type=type_string, pointer=CPointer(_type=CPointerType.SINGLE)), - CArg(name="prev", _type=f"{type_string}Node", pointer=CPointer(_type=CPointerType.SINGLE)), - CArg(name="next", _type=f"{type_string}Node", pointer=CPointer(_type=CPointerType.SINGLE)), ], ) + node.cargs.extend([ + CArg(name="prev", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)), + CArg(name="next", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)), + ]) dl_list = CStruct( - name=f"{type_string}List", + name=f"{type_string.title()}List", cargs=[ CArg(name="first", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)), CArg(name="last", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)), @@ -77,6 +78,15 @@ def gen_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}): ], ) + node_func = CFunc( + name=f"wapp_{type_string.lower()}_list_node", + ret_type=node, + args=[ + CArg(name="item", _type=type_string, pointer=CPointer(CPointerType.SINGLE)), + ], + body=__format_func_body(snippets_dir / "list_node", type_string), + ) + get_func = CFunc( name=f"wapp_{type_string.lower()}_list_get", ret_type=node, @@ -175,6 +185,7 @@ def gen_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}): includes=[], types=[node, dl_list], funcs=[ + node_func, get_func, push_front_func, push_back_func, @@ -198,6 +209,11 @@ def gen_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}): header.includes.extend(common_includes) source.includes.extend(common_includes) + for include_file in common_local_include_files: + include = CInclude(header=str(include_file.relative_to(dbl_list_data.out_dir, walk_up=True)), local=True) + header.includes.append(include) + source.includes.append(include) + if len(dbl_list_data.hdr_includes) > 0: header.includes.extend(dbl_list_data.hdr_includes) diff --git a/codegen/dbl_list/snippets/list_get b/codegen/dbl_list/snippets/list_get index c65985e..0fde3ac 100644 --- a/codegen/dbl_list/snippets/list_get +++ b/codegen/dbl_list/snippets/list_get @@ -2,8 +2,8 @@ return NULL; }} - {T}Node *output = NULL; - {T}Node *current = list->first; + {Ttitle}Node *output = NULL; + {Ttitle}Node *current = list->first; for (u64 i = 1; i <= index; ++i) {{ current = current->next; }} diff --git a/codegen/dbl_list/snippets/list_insert b/codegen/dbl_list/snippets/list_insert index e8eb294..5ae0d84 100644 --- a/codegen/dbl_list/snippets/list_insert +++ b/codegen/dbl_list/snippets/list_insert @@ -10,16 +10,16 @@ return; }} - {T}Node *dst_node = wapp_{Tlower}_list_get(list, index); + {Ttitle}Node *dst_node = wapp_{Tlower}_list_get(list, index); if (!dst_node) {{ return; }} - {T}List node_list = {Tlower}_node_to_list(node); + {Ttitle}List node_list = {Tlower}_node_to_list(node); list->node_count += node_list.node_count; - {T}Node *prev = dst_node->prev; + {Ttitle}Node *prev = dst_node->prev; dst_node->prev = node_list.last; prev->next = node_list.first; diff --git a/codegen/dbl_list/snippets/list_node b/codegen/dbl_list/snippets/list_node new file mode 100644 index 0000000..8a9e407 --- /dev/null +++ b/codegen/dbl_list/snippets/list_node @@ -0,0 +1 @@ + return ({Ttitle}Node){{.item = item}}; diff --git a/codegen/dbl_list/snippets/list_pop_back b/codegen/dbl_list/snippets/list_pop_back index 67e370a..849136d 100644 --- a/codegen/dbl_list/snippets/list_pop_back +++ b/codegen/dbl_list/snippets/list_pop_back @@ -1,4 +1,4 @@ - {T}Node *output = NULL; + {Ttitle}Node *output = NULL; if (!list || list->node_count == 0) {{ goto RETURN_{Tupper}_LIST_POP_BACK; @@ -7,7 +7,7 @@ output = list->last; if (list->node_count == 1) {{ - *list = ({T}List){{0}}; + *list = ({Ttitle}List){{0}}; goto RETURN_{Tupper}_LIST_POP_BACK; }} diff --git a/codegen/dbl_list/snippets/list_pop_front b/codegen/dbl_list/snippets/list_pop_front index 97de159..8770e3f 100644 --- a/codegen/dbl_list/snippets/list_pop_front +++ b/codegen/dbl_list/snippets/list_pop_front @@ -1,4 +1,4 @@ - {T}Node *output = NULL; + {Ttitle}Node *output = NULL; if (!list || list->node_count == 0) {{ goto RETURN_{Tupper}_LIST_POP_FRONT; @@ -7,7 +7,7 @@ output = list->first; if (list->node_count == 1) {{ - *list = ({T}List){{0}}; + *list = ({Ttitle}List){{0}}; goto RETURN_{Tupper}_LIST_POP_FRONT; }} diff --git a/codegen/dbl_list/snippets/list_push_back b/codegen/dbl_list/snippets/list_push_back index 4d7b004..35abf52 100644 --- a/codegen/dbl_list/snippets/list_push_back +++ b/codegen/dbl_list/snippets/list_push_back @@ -2,7 +2,7 @@ return; }} - {T}List node_list = {Tlower}_node_to_list(node); + {Ttitle}List node_list = {Tlower}_node_to_list(node); if (list->node_count == 0) {{ *list = node_list; @@ -11,7 +11,7 @@ list->node_count += node_list.node_count; - {T}Node *last = list->last; + {Ttitle}Node *last = list->last; if (last) {{ last->next = node_list.first; }} diff --git a/codegen/dbl_list/snippets/list_push_front b/codegen/dbl_list/snippets/list_push_front index 784f669..f021cfc 100644 --- a/codegen/dbl_list/snippets/list_push_front +++ b/codegen/dbl_list/snippets/list_push_front @@ -2,7 +2,7 @@ return; }} - {T}List node_list = {Tlower}_node_to_list(node); + {Ttitle}List node_list = {Tlower}_node_to_list(node); if (list->node_count == 0) {{ *list = node_list; @@ -11,7 +11,7 @@ list->node_count += node_list.node_count; - {T}Node *first = list->first; + {Ttitle}Node *first = list->first; if (first) {{ first->prev = node_list.last; }} diff --git a/codegen/dbl_list/snippets/list_remove b/codegen/dbl_list/snippets/list_remove index 90095b5..611729a 100644 --- a/codegen/dbl_list/snippets/list_remove +++ b/codegen/dbl_list/snippets/list_remove @@ -1,4 +1,4 @@ - {T}Node *output = NULL; + {Ttitle}Node *output = NULL; if (!list) {{ goto RETURN_{Tupper}_LIST_REMOVE; }} diff --git a/codegen/dbl_list/snippets/node_to_list b/codegen/dbl_list/snippets/node_to_list index b11a634..b47d7e5 100644 --- a/codegen/dbl_list/snippets/node_to_list +++ b/codegen/dbl_list/snippets/node_to_list @@ -1,4 +1,4 @@ - {T}List output = {{.first = node, .last = node, .node_count = 1}}; + {Ttitle}List output = {{.first = node, .last = node, .node_count = 1}}; while (output.first->prev != NULL) {{ output.first = output.first->prev; diff --git a/codegen/utils.py b/codegen/utils.py index 47b6b16..8a8c814 100644 --- a/codegen/utils.py +++ b/codegen/utils.py @@ -3,4 +3,4 @@ from pathlib import Path def load_func_body_from_file(filename: Path) -> str: with open(filename, "r") as infile: - return infile.read().strip() + return infile.read().rstrip() diff --git a/src/core/strings/str8/str8_list.c b/src/core/strings/str8/str8_list.c index a648311..0950acd 100644 --- a/src/core/strings/str8/str8_list.c +++ b/src/core/strings/str8/str8_list.c @@ -4,13 +4,16 @@ #include "./str8_list.h" #include "../../../common/aliases/aliases.h" -#include "./str8.h" #include internal Str8List str8_node_to_list(Str8Node *node); +Str8Node wapp_str8_list_node(Str8 *item) { + return (Str8Node){.item = item}; +} + Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) { -if (index >= list->node_count) { + if (index >= list->node_count) { return NULL; } @@ -26,7 +29,7 @@ if (index >= list->node_count) { } void wapp_str8_list_push_front(Str8List *list, Str8Node *node) { -if (!list || !node || !(node->item)) { + if (!list || !node || !(node->item)) { return; } @@ -49,7 +52,7 @@ if (!list || !node || !(node->item)) { } void wapp_str8_list_push_back(Str8List *list, Str8Node *node) { -if (!list || !node || !(node->item)) { + if (!list || !node || !(node->item)) { return; } @@ -72,7 +75,7 @@ if (!list || !node || !(node->item)) { } void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) { -if (!list || !node || !(node->item)) { + if (!list || !node || !(node->item)) { return; } @@ -103,7 +106,7 @@ if (!list || !node || !(node->item)) { } Str8Node *wapp_str8_list_pop_front(Str8List *list) { -Str8Node *output = NULL; + Str8Node *output = NULL; if (!list || list->node_count == 0) { goto RETURN_STR8_LIST_POP_FRONT; @@ -126,7 +129,7 @@ RETURN_STR8_LIST_POP_FRONT: } Str8Node *wapp_str8_list_pop_back(Str8List *list) { -Str8Node *output = NULL; + Str8Node *output = NULL; if (!list || list->node_count == 0) { goto RETURN_STR8_LIST_POP_BACK; @@ -149,7 +152,7 @@ RETURN_STR8_LIST_POP_BACK: } Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) { -Str8Node *output = NULL; + Str8Node *output = NULL; if (!list) { goto RETURN_STR8_LIST_REMOVE; } @@ -179,7 +182,7 @@ RETURN_STR8_LIST_REMOVE: } void wapp_str8_list_empty(Str8List *list) { -if (!list) { + if (!list) { return; } @@ -190,7 +193,7 @@ if (!list) { } internal Str8List str8_node_to_list(Str8Node *node) { -Str8List output = {.first = node, .last = node, .node_count = 1}; + Str8List output = {.first = node, .last = node, .node_count = 1}; while (output.first->prev != NULL) { output.first = output.first->prev; diff --git a/src/core/strings/str8/str8_list.h b/src/core/strings/str8/str8_list.h index 529c5c0..7c816b2 100644 --- a/src/core/strings/str8/str8_list.h +++ b/src/core/strings/str8/str8_list.h @@ -27,6 +27,7 @@ struct Str8List { u64 node_count; }; +Str8Node wapp_str8_list_node(Str8 *item); Str8Node *wapp_str8_list_get(const Str8List *list, u64 index); void wapp_str8_list_push_front(Str8List *list, Str8Node *node); void wapp_str8_list_push_back(Str8List *list, Str8Node *node); From 63ed2633eae9215fe542d51759e849ab2e5c8855 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sat, 19 Apr 2025 13:33:09 +0100 Subject: [PATCH 6/6] Update code generation to create one file for dbl_list --- codegen/__main__.py | 1 - codegen/datatypes.py | 24 ++++ codegen/dbl_list/make_dbl_list.py | 104 +++++++++--------- codegen/dbl_list/snippets/list_node | 2 +- .../dbl_list/dbl_list.c} | 10 +- .../dbl_list/dbl_list.h} | 11 +- src/containers/wapp_containers.c | 6 + src/containers/wapp_containers.h | 7 ++ src/core/strings/str8/str8.h | 6 +- src/core/wapp_core.c | 2 +- src/core/wapp_core.h | 2 +- 11 files changed, 105 insertions(+), 70 deletions(-) rename src/{core/strings/str8/str8_list.c => containers/dbl_list/dbl_list.c} (96%) rename src/{core/strings/str8/str8_list.h => containers/dbl_list/dbl_list.h} (84%) create mode 100644 src/containers/wapp_containers.c create mode 100644 src/containers/wapp_containers.h diff --git a/codegen/__main__.py b/codegen/__main__.py index b03bdc9..4d833c3 100644 --- a/codegen/__main__.py +++ b/codegen/__main__.py @@ -8,7 +8,6 @@ def main(): def gen_dbl_list(): datatypes: dict[CDataType, DblListData] = {} - make_dbl_list(datatypes) diff --git a/codegen/datatypes.py b/codegen/datatypes.py index fab1b9d..e28f258 100644 --- a/codegen/datatypes.py +++ b/codegen/datatypes.py @@ -88,6 +88,15 @@ class CEnum: return header + values + footer +@dataclass +class CMacro: + name: str + value: str + + def __str__(self) -> str: + return f"#define {self.name} {self.value}\n" + + @dataclass class CStruct: name: str @@ -195,6 +204,7 @@ class CFile: name: str extension: str decl_types: list[CStruct] = field(default_factory=list) + macros: list[CMacro] = field(default_factory=list) def save(self, output_dir: Path): output_file = output_dir / f"{self.name}.{self.extension}" @@ -228,6 +238,12 @@ class CHeader(CFile): includes = _get_includes_string(self.includes) + macros = "" + for macro in self.macros: + macros += str(macro) + if len(macros) > 0: + macros += "\n" + forward_declarations = "" for _type in self.decl_types: forward_declarations += _type.declare() @@ -247,6 +263,7 @@ class CHeader(CFile): header_guard_open + includes + c_linkage_open + + macros + forward_declarations + types + funcs + @@ -266,6 +283,12 @@ class CSource(CFile): def __str__(self) -> str: includes = _get_includes_string(self.includes) + macros = "" + for macro in self.macros: + macros += str(macro) + if len(macros) > 0: + macros += "\n" + forward_declarations = "" for _type in self.decl_types: forward_declarations += _type.declare() @@ -292,6 +315,7 @@ class CSource(CFile): return ( super().__str__() + includes + + macros + forward_declarations + types + internal_funcs_decl + diff --git a/codegen/dbl_list/make_dbl_list.py b/codegen/dbl_list/make_dbl_list.py index f979e2c..e7f9111 100644 --- a/codegen/dbl_list/make_dbl_list.py +++ b/codegen/dbl_list/make_dbl_list.py @@ -4,6 +4,7 @@ from codegen.constants import WAPP_SRC_ROOT from codegen.utils import load_func_body_from_file from codegen.datatypes import ( CDataType, + CMacro, CStruct, CFunc, CHeader, @@ -20,9 +21,6 @@ from codegen.datatypes import ( @dataclass class DblListData: - out_dir: Path - hdr_includes: list[CInclude] = field(default_factory=list) - src_includes: list[CInclude] = field(default_factory=list) hdr_decl_types: list[CStruct] = field(default_factory=list) src_decl_types: list[CStruct] = field(default_factory=list) @@ -36,10 +34,20 @@ def make_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}): Tlower=type_string.lower(), ) + out_dir = WAPP_SRC_ROOT / "containers" / "dbl_list" + out_dir.mkdir(parents=True, exist_ok=True) + common_local_include_files = [ (WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h") ] common_includes: list[CInclude] = [] + for local_file in common_local_include_files: + common_includes.append( + CInclude( + header=str(local_file.relative_to(out_dir, walk_up=True)), + local=True, + ) + ) common_decl_types: list[CStruct] = [] @@ -48,13 +56,32 @@ def make_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}): hdr_decl_types=[ CStruct(name="str8", cargs=[], typedef_name="Str8"), ], - out_dir=WAPP_SRC_ROOT / "core" / "strings" / "str8", ), } datatypes.update(user_datatypes) snippets_dir = Path(__file__).parent / "snippets" + header = CHeader( + name="dbl_list", + decl_types=common_decl_types, + includes=[], + types=[], + funcs=[] + ) + + source = CSource( + name=header.name, + decl_types=common_decl_types, + includes=[CInclude(header, local=True, same_dir=True), CInclude(header="stddef.h")], + internal_funcs=[], + funcs=header.funcs + ) + + if len(common_includes) > 0: + header.includes.extend(common_includes) + source.includes.extend(common_includes) + for _type, dbl_list_data in datatypes.items(): type_string = get_datatype_string(_type) @@ -78,13 +105,9 @@ def make_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}): ], ) - node_func = CFunc( - name=f"wapp_{type_string.lower()}_list_node", - ret_type=node, - args=[ - CArg(name="item", _type=type_string, pointer=CPointer(CPointerType.SINGLE)), - ], - body=__format_func_body(snippets_dir / "list_node", type_string), + node_macro = CMacro( + name=f"wapp_{type_string.lower()}_list_node(ITEM_PTR)", + value=__format_func_body(snippets_dir / "list_node", type_string), ) get_func = CFunc( @@ -179,46 +202,23 @@ def make_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}): qualifiers=[CQualifier.INTERNAL], ) - header = CHeader( - name=f"{type_string.lower()}_list", - decl_types=common_decl_types + dbl_list_data.hdr_decl_types, - includes=[], - types=[node, dl_list], - funcs=[ - node_func, - get_func, - push_front_func, - push_back_func, - insert_func, - pop_front_func, - pop_back_func, - remove_func, - empty_func, - ] - ) + header.decl_types.extend(dbl_list_data.hdr_decl_types) + header.macros.append(node_macro) + header.types.extend([node, dl_list]) + header.funcs.extend([ + get_func, + push_front_func, + push_back_func, + insert_func, + pop_front_func, + pop_back_func, + remove_func, + empty_func, + ]) - source = CSource( - name=header.name, - decl_types=common_decl_types + dbl_list_data.src_decl_types, - includes=[CInclude(header, local=True, same_dir=True), CInclude(header="stddef.h")], - internal_funcs=[node_to_list_func], - funcs=header.funcs - ) + source.decl_types.extend(dbl_list_data.src_decl_types) + source.internal_funcs.append(node_to_list_func) + source.funcs = header.funcs - if len(common_includes) > 0: - header.includes.extend(common_includes) - source.includes.extend(common_includes) - - for include_file in common_local_include_files: - include = CInclude(header=str(include_file.relative_to(dbl_list_data.out_dir, walk_up=True)), local=True) - header.includes.append(include) - source.includes.append(include) - - if len(dbl_list_data.hdr_includes) > 0: - header.includes.extend(dbl_list_data.hdr_includes) - - if len(dbl_list_data.src_includes) > 0: - source.includes.extend(dbl_list_data.src_includes) - - header.save(dbl_list_data.out_dir) - source.save(dbl_list_data.out_dir) + header.save(out_dir) + source.save(out_dir) diff --git a/codegen/dbl_list/snippets/list_node b/codegen/dbl_list/snippets/list_node index 8a9e407..b689b0e 100644 --- a/codegen/dbl_list/snippets/list_node +++ b/codegen/dbl_list/snippets/list_node @@ -1 +1 @@ - return ({Ttitle}Node){{.item = item}}; +(({Ttitle}Node){{.item = ITEM_PTR}}) diff --git a/src/core/strings/str8/str8_list.c b/src/containers/dbl_list/dbl_list.c similarity index 96% rename from src/core/strings/str8/str8_list.c rename to src/containers/dbl_list/dbl_list.c index 0950acd..9ddc08e 100644 --- a/src/core/strings/str8/str8_list.c +++ b/src/containers/dbl_list/dbl_list.c @@ -2,15 +2,13 @@ * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN */ -#include "./str8_list.h" -#include "../../../common/aliases/aliases.h" +#include "./dbl_list.h" +#include "../../common/aliases/aliases.h" #include -internal Str8List str8_node_to_list(Str8Node *node); +typedef struct str8 Str8; -Str8Node wapp_str8_list_node(Str8 *item) { - return (Str8Node){.item = item}; -} +internal Str8List str8_node_to_list(Str8Node *node); Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) { if (index >= list->node_count) { diff --git a/src/core/strings/str8/str8_list.h b/src/containers/dbl_list/dbl_list.h similarity index 84% rename from src/core/strings/str8/str8_list.h rename to src/containers/dbl_list/dbl_list.h index 7c816b2..a99121e 100644 --- a/src/core/strings/str8/str8_list.h +++ b/src/containers/dbl_list/dbl_list.h @@ -2,15 +2,17 @@ * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN */ -#ifndef STR8_LIST_H -#define STR8_LIST_H +#ifndef DBL_LIST_H +#define DBL_LIST_H -#include "../../../common/aliases/aliases.h" +#include "../../common/aliases/aliases.h" #ifdef __cplusplus BEGIN_C_LINKAGE #endif // !__cplusplus +#define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR}) + typedef struct str8 Str8; typedef struct Str8Node Str8Node; @@ -27,7 +29,6 @@ struct Str8List { u64 node_count; }; -Str8Node wapp_str8_list_node(Str8 *item); Str8Node *wapp_str8_list_get(const Str8List *list, u64 index); void wapp_str8_list_push_front(Str8List *list, Str8Node *node); void wapp_str8_list_push_back(Str8List *list, Str8Node *node); @@ -41,4 +42,4 @@ void wapp_str8_list_empty(Str8List *list); END_C_LINKAGE #endif // !__cplusplus -#endif // !STR8_LIST_H +#endif // !DBL_LIST_H diff --git a/src/containers/wapp_containers.c b/src/containers/wapp_containers.c new file mode 100644 index 0000000..6fc30b2 --- /dev/null +++ b/src/containers/wapp_containers.c @@ -0,0 +1,6 @@ +#ifndef WAPP_CONTAINERS_C +#define WAPP_CONTAINERS_C + +#include "dbl_list/dbl_list.c" + +#endif // !WAPP_CONTAINERS_C diff --git a/src/containers/wapp_containers.h b/src/containers/wapp_containers.h new file mode 100644 index 0000000..0c48a9f --- /dev/null +++ b/src/containers/wapp_containers.h @@ -0,0 +1,7 @@ +#ifndef WAPP_CONTAINERS_H +#define WAPP_CONTAINERS_H + +#include "dbl_list/dbl_list.h" +#include "../common/wapp_common.h" + +#endif // !WAPP_CONTAINERS_H diff --git a/src/core/strings/str8/str8.h b/src/core/strings/str8/str8.h index 725b65d..647b795 100644 --- a/src/core/strings/str8/str8.h +++ b/src/core/strings/str8/str8.h @@ -1,8 +1,8 @@ #ifndef STR8_H #define STR8_H -#include "./str8_list.h" #include "../../../common/aliases/aliases.h" +#include "../../../containers/dbl_list/dbl_list.h" #include "../../mem/allocator/mem_allocator.h" #include #include @@ -91,8 +91,8 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8R /** * Str8 list utilities */ -#define wapp_str8_node_from_cstr(STRING) ((Str8Node){.item = &wapp_str8_lit(STRING)}) -#define wapp_str8_node_from_str8(STRING) ((Str8Node){.item = &(STRING)}) +#define wapp_str8_node_from_cstr(STRING) wapp_str8_list_node(&wapp_str8_lit(STRING)) +#define wapp_str8_node_from_str8(STRING) wapp_str8_list_node(&(STRING)) u64 wapp_str8_list_total_size(const Str8List *list); #ifdef __cplusplus diff --git a/src/core/wapp_core.c b/src/core/wapp_core.c index d41bc27..dfab160 100644 --- a/src/core/wapp_core.c +++ b/src/core/wapp_core.c @@ -3,7 +3,6 @@ #include "wapp_core.h" #include "strings/str8/str8.c" -#include "strings/str8/str8_list.c" #include "os/shell/termcolour/posix/termcolour_posix.c" #include "os/shell/termcolour/win/termcolour_win.c" #include "os/shell/termcolour/termcolour.c" @@ -18,5 +17,6 @@ #include "mem/allocator/mem_allocator.c" #include "mem/arena/mem_arena.c" #include "mem/arena/mem_arena_allocator.c" +#include "../containers/wapp_containers.c" #endif // !WAPP_CORE_C diff --git a/src/core/wapp_core.h b/src/core/wapp_core.h index d698b47..e1903a9 100644 --- a/src/core/wapp_core.h +++ b/src/core/wapp_core.h @@ -2,7 +2,6 @@ #define WAPP_CORE_H #include "strings/str8/str8.h" -#include "strings/str8/str8_list.h" #include "os/shell/termcolour/termcolour.h" #include "os/shell/termcolour/terminal_colours.h" #include "os/shell/commander/commander.h" @@ -18,5 +17,6 @@ #include "mem/arena/mem_arena_allocator.h" #include "mem/arena/mem_arena.h" #include "../common/wapp_common.h" +#include "../containers/wapp_containers.h" #endif // !WAPP_CORE_H