Fix codegen hidden bugs
This commit is contained in:
parent
0942643b4e
commit
cfa8094260
@ -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)
|
||||
|
@ -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);
|
||||
}}
|
||||
|
@ -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;
|
||||
|
@ -12,7 +12,6 @@
|
||||
}}
|
||||
|
||||
--(list->node_count);
|
||||
list->total_size -= output->string->size;
|
||||
list->last = output->prev;
|
||||
|
||||
output->prev = output->next = NULL;
|
||||
|
@ -12,7 +12,6 @@
|
||||
}}
|
||||
|
||||
--(list->node_count);
|
||||
list->total_size -= output->string->size;
|
||||
list->first = output->next;
|
||||
|
||||
output->prev = output->next = NULL;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}}
|
||||
|
Loading…
Reference in New Issue
Block a user