Fix codegen hidden bugs
This commit is contained in:
parent
0942643b4e
commit
cfa8094260
@ -21,15 +21,13 @@ from codegen.datatypes import (
|
|||||||
@dataclass
|
@dataclass
|
||||||
class DblListData:
|
class DblListData:
|
||||||
out_dir: Path
|
out_dir: Path
|
||||||
common_includes: list[CInclude] = field(default_factory=list)
|
|
||||||
hdr_includes: list[CInclude] = field(default_factory=list)
|
hdr_includes: list[CInclude] = field(default_factory=list)
|
||||||
src_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)
|
hdr_decl_types: list[CStruct] = field(default_factory=list)
|
||||||
src_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):
|
def __format_func_body(filename: Path, type_string: str):
|
||||||
return load_func_body_from_file(filename).format(
|
return load_func_body_from_file(filename).format(
|
||||||
T=type_string,
|
T=type_string,
|
||||||
@ -37,11 +35,14 @@ def gen_dbl_list():
|
|||||||
Tlower=type_string.lower(),
|
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] = {
|
datatypes: dict[CDataType, DblListData] = {
|
||||||
"Str8": DblListData(
|
"Str8": DblListData(
|
||||||
common_includes=[
|
|
||||||
CInclude(header="../../../common/aliases/aliases.h", local=True),
|
|
||||||
],
|
|
||||||
src_includes=[
|
src_includes=[
|
||||||
CInclude(header="./str8.h", local=True),
|
CInclude(header="./str8.h", local=True),
|
||||||
],
|
],
|
||||||
@ -51,6 +52,8 @@ def gen_dbl_list():
|
|||||||
out_dir=WAPP_SRC_ROOT / "core/strings/str8/",
|
out_dir=WAPP_SRC_ROOT / "core/strings/str8/",
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
datatypes.update(user_datatypes)
|
||||||
|
|
||||||
snippets_dir = Path(__file__).parent / "snippets"
|
snippets_dir = Path(__file__).parent / "snippets"
|
||||||
|
|
||||||
for _type, dbl_list_data in datatypes.items():
|
for _type, dbl_list_data in datatypes.items():
|
||||||
@ -59,7 +62,7 @@ def gen_dbl_list():
|
|||||||
node = CStruct(
|
node = CStruct(
|
||||||
name=f"{type_string}Node",
|
name=f"{type_string}Node",
|
||||||
cargs=[
|
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="prev", _type=f"{type_string}Node", pointer=CPointer(_type=CPointerType.SINGLE)),
|
||||||
CArg(name="next", _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=[
|
cargs=[
|
||||||
CArg(name="first", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)),
|
CArg(name="first", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)),
|
||||||
CArg(name="last", _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),
|
CArg(name="node_count", _type=CType.U64),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -169,7 +171,7 @@ def gen_dbl_list():
|
|||||||
|
|
||||||
header = CHeader(
|
header = CHeader(
|
||||||
name=f"{type_string.lower()}_list",
|
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=[],
|
includes=[],
|
||||||
types=[node, dl_list],
|
types=[node, dl_list],
|
||||||
funcs=[
|
funcs=[
|
||||||
@ -186,15 +188,15 @@ def gen_dbl_list():
|
|||||||
|
|
||||||
source = CSource(
|
source = CSource(
|
||||||
name=header.name,
|
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")],
|
includes=[CInclude(header, local=True, same_dir=True), CInclude(header="stddef.h")],
|
||||||
internal_funcs=[node_to_list_func],
|
internal_funcs=[node_to_list_func],
|
||||||
funcs=header.funcs
|
funcs=header.funcs
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(dbl_list_data.common_includes) > 0:
|
if len(common_includes) > 0:
|
||||||
header.includes.extend(dbl_list_data.common_includes)
|
header.includes.extend(common_includes)
|
||||||
source.includes.extend(dbl_list_data.common_includes)
|
source.includes.extend(common_includes)
|
||||||
|
|
||||||
if len(dbl_list_data.hdr_includes) > 0:
|
if len(dbl_list_data.hdr_includes) > 0:
|
||||||
header.includes.extend(dbl_list_data.hdr_includes)
|
header.includes.extend(dbl_list_data.hdr_includes)
|
||||||
|
@ -4,5 +4,5 @@
|
|||||||
|
|
||||||
u64 count = list->node_count;
|
u64 count = list->node_count;
|
||||||
for (u64 i = 0; i < count; ++i) {{
|
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;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
if (index == 0) {{
|
if (index == 0) {{
|
||||||
wapp_str8_list_push_front(list, node);
|
wapp_{T}_list_push_front(list, node);
|
||||||
return;
|
return;
|
||||||
}} else if (index == list->node_count) {{
|
}} else if (index == list->node_count) {{
|
||||||
wapp_str8_list_push_back(list, node);
|
wapp_{T}_list_push_back(list, node);
|
||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
{T}Node *dst_node = wapp_str8_list_get(list, index);
|
{T}Node *dst_node = wapp_{T}_list_get(list, index);
|
||||||
if (!dst_node) {{
|
if (!dst_node) {{
|
||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
{T}List node_list = {Tlower}_node_to_list(node);
|
{T}List node_list = {Tlower}_node_to_list(node);
|
||||||
|
|
||||||
list->total_size += node_list.total_size;
|
|
||||||
list->node_count += node_list.node_count;
|
list->node_count += node_list.node_count;
|
||||||
|
|
||||||
{T}Node *prev = dst_node->prev;
|
{T}Node *prev = dst_node->prev;
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
--(list->node_count);
|
--(list->node_count);
|
||||||
list->total_size -= output->string->size;
|
|
||||||
list->last = output->prev;
|
list->last = output->prev;
|
||||||
|
|
||||||
output->prev = output->next = NULL;
|
output->prev = output->next = NULL;
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
--(list->node_count);
|
--(list->node_count);
|
||||||
list->total_size -= output->string->size;
|
|
||||||
list->first = output->next;
|
list->first = output->next;
|
||||||
|
|
||||||
output->prev = output->next = NULL;
|
output->prev = output->next = NULL;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
if (!list || !node || !(node->string)) {{
|
if (!list || !node || !(node->item)) {{
|
||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@ -9,7 +9,6 @@
|
|||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
list->total_size += node_list.total_size;
|
|
||||||
list->node_count += node_list.node_count;
|
list->node_count += node_list.node_count;
|
||||||
|
|
||||||
{T}Node *last = list->last;
|
{T}Node *last = list->last;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
if (!list || !node || !(node->string)) {{
|
if (!list || !node || !(node->item)) {{
|
||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@ -9,7 +9,6 @@
|
|||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
list->total_size += node_list.total_size;
|
|
||||||
list->node_count += node_list.node_count;
|
list->node_count += node_list.node_count;
|
||||||
|
|
||||||
{T}Node *first = list->first;
|
{T}Node *first = list->first;
|
||||||
|
@ -4,14 +4,14 @@
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
if (index == 0) {{
|
if (index == 0) {{
|
||||||
output = wapp_str8_list_pop_front(list);
|
output = wapp_{T}_list_pop_front(list);
|
||||||
goto RETURN_{Tupper}_LIST_REMOVE;
|
goto RETURN_{Tupper}_LIST_REMOVE;
|
||||||
}} else if (index == list->node_count) {{
|
}} 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;
|
goto RETURN_{Tupper}_LIST_REMOVE;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
output = wapp_str8_list_get(list, index);
|
output = wapp_{T}_list_get(list, index);
|
||||||
if (!output) {{
|
if (!output) {{
|
||||||
goto RETURN_{Tupper}_LIST_REMOVE;
|
goto RETURN_{Tupper}_LIST_REMOVE;
|
||||||
}}
|
}}
|
||||||
@ -20,7 +20,6 @@
|
|||||||
output->next->prev = output->prev;
|
output->next->prev = output->prev;
|
||||||
|
|
||||||
--(list->node_count);
|
--(list->node_count);
|
||||||
list->total_size -= output->string->size;
|
|
||||||
|
|
||||||
output->prev = output->next = NULL;
|
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) {{
|
while (output.first->prev != NULL) {{
|
||||||
output.total_size += output.first->prev->string->size;
|
|
||||||
output.first = output.first->prev;
|
output.first = output.first->prev;
|
||||||
++(output.node_count);
|
++(output.node_count);
|
||||||
}}
|
}}
|
||||||
|
|
||||||
while (output.last->next != NULL) {{
|
while (output.last->next != NULL) {{
|
||||||
output.total_size += output.last->next->string->size;
|
|
||||||
output.last = output.last->next;
|
output.last = output.last->next;
|
||||||
++(output.node_count);
|
++(output.node_count);
|
||||||
}}
|
}}
|
||||||
|
Loading…
Reference in New Issue
Block a user