Update codegen
This commit is contained in:
@@ -67,6 +67,9 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
|
|||||||
common_decl_types: List[CStruct] = []
|
common_decl_types: List[CStruct] = []
|
||||||
|
|
||||||
datatypes: dict[CDataType, ArrayData] = {
|
datatypes: dict[CDataType, ArrayData] = {
|
||||||
|
CType.VOID: ArrayData(
|
||||||
|
array_typename="GenericArray",
|
||||||
|
),
|
||||||
"Str8": ArrayData(
|
"Str8": ArrayData(
|
||||||
array_typename="Str8Array",
|
array_typename="Str8Array",
|
||||||
hdr_decl_types=[
|
hdr_decl_types=[
|
||||||
@@ -77,13 +80,10 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
|
|||||||
|
|
||||||
for _type in CType:
|
for _type in CType:
|
||||||
if _type == CType.VOID:
|
if _type == CType.VOID:
|
||||||
datatypes[_type.value] = ArrayData(
|
|
||||||
array_typename="GenericArray",
|
|
||||||
)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
type_title = _type.value.title()
|
type_title = _type.value.title()
|
||||||
datatypes[_type.value] = ArrayData(
|
datatypes[_type] = ArrayData(
|
||||||
array_typename=f"{type_title}Array",
|
array_typename=f"{type_title}Array",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(_type, str) and _type == CType.VOID.value:
|
if isinstance(_type, CType) and _type == CType.VOID:
|
||||||
alloc_capacity_func = CFunc(
|
alloc_capacity_func = CFunc(
|
||||||
name=f"_array_alloc_capacity",
|
name=f"_array_alloc_capacity",
|
||||||
ret_type=array,
|
ret_type=array,
|
||||||
|
@@ -59,6 +59,10 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
|||||||
common_decl_types: List[CStruct] = []
|
common_decl_types: List[CStruct] = []
|
||||||
|
|
||||||
datatypes: dict[CDataType, DblListData] = {
|
datatypes: dict[CDataType, DblListData] = {
|
||||||
|
CType.VOID: DblListData(
|
||||||
|
node_typename="GenericNode",
|
||||||
|
list_typename="GenericList",
|
||||||
|
),
|
||||||
"Str8": DblListData(
|
"Str8": DblListData(
|
||||||
node_typename="Str8Node",
|
node_typename="Str8Node",
|
||||||
list_typename="Str8List",
|
list_typename="Str8List",
|
||||||
@@ -70,14 +74,10 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
|||||||
|
|
||||||
for _type in CType:
|
for _type in CType:
|
||||||
if _type == CType.VOID:
|
if _type == CType.VOID:
|
||||||
datatypes["void *"] = DblListData(
|
|
||||||
node_typename="VoidPNode",
|
|
||||||
list_typename="VoidPList",
|
|
||||||
)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
type_title = _type.value.title()
|
type_title = _type.value.title()
|
||||||
datatypes[_type.value] = DblListData(
|
datatypes[_type] = DblListData(
|
||||||
node_typename=f"{type_title}Node",
|
node_typename=f"{type_title}Node",
|
||||||
list_typename=f"{type_title}List",
|
list_typename=f"{type_title}List",
|
||||||
)
|
)
|
||||||
@@ -135,6 +135,13 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
header.types.extend([node, dl_list])
|
||||||
|
header.decl_types.extend(dbl_list_data.hdr_decl_types)
|
||||||
|
source.decl_types.extend(dbl_list_data.src_decl_types)
|
||||||
|
if isinstance(_type, CType) and _type == CType.VOID:
|
||||||
|
# Don't define any functions for the generic node and list
|
||||||
|
continue
|
||||||
|
|
||||||
node_cmacro = CMacro(
|
node_cmacro = CMacro(
|
||||||
name=f"wapp_{type_string_lower}_list_node(ITEM_PTR)",
|
name=f"wapp_{type_string_lower}_list_node(ITEM_PTR)",
|
||||||
value=__format_func_body(
|
value=__format_func_body(
|
||||||
@@ -314,10 +321,8 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
|||||||
qualifiers=[CQualifier.INTERNAL],
|
qualifiers=[CQualifier.INTERNAL],
|
||||||
)
|
)
|
||||||
|
|
||||||
header.decl_types.extend(dbl_list_data.hdr_decl_types)
|
|
||||||
header.c_macros.append(node_cmacro)
|
header.c_macros.append(node_cmacro)
|
||||||
header.cpp_macros.append(node_cppmacro)
|
header.cpp_macros.append(node_cppmacro)
|
||||||
header.types.extend([node, dl_list])
|
|
||||||
header.funcs.extend([
|
header.funcs.extend([
|
||||||
get_func,
|
get_func,
|
||||||
push_front_func,
|
push_front_func,
|
||||||
@@ -329,7 +334,6 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
|||||||
empty_func,
|
empty_func,
|
||||||
])
|
])
|
||||||
|
|
||||||
source.decl_types.extend(dbl_list_data.src_decl_types)
|
|
||||||
source.internal_funcs.append(node_to_list_func)
|
source.internal_funcs.append(node_to_list_func)
|
||||||
source.funcs = header.funcs
|
source.funcs = header.funcs
|
||||||
|
|
||||||
|
@@ -572,17 +572,17 @@ BEGIN_C_LINKAGE
|
|||||||
|
|
||||||
typedef struct str8 Str8;
|
typedef struct str8 Str8;
|
||||||
|
|
||||||
typedef struct Str8Array Str8Array;
|
typedef struct GenericArray GenericArray;
|
||||||
struct Str8Array {
|
struct GenericArray {
|
||||||
Str8 *items;
|
void *items;
|
||||||
u64 count;
|
u64 count;
|
||||||
u64 capacity;
|
u64 capacity;
|
||||||
u64 item_size;
|
u64 item_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct GenericArray GenericArray;
|
typedef struct Str8Array Str8Array;
|
||||||
struct GenericArray {
|
struct Str8Array {
|
||||||
void *items;
|
Str8 *items;
|
||||||
u64 count;
|
u64 count;
|
||||||
u64 capacity;
|
u64 capacity;
|
||||||
u64 item_size;
|
u64 item_size;
|
||||||
|
@@ -9,7 +9,6 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
internal Str8List str8_node_to_list(Str8Node *node);
|
internal Str8List str8_node_to_list(Str8Node *node);
|
||||||
internal VoidPList void_ptr_node_to_list(VoidPNode *node);
|
|
||||||
internal B32List b32_node_to_list(B32Node *node);
|
internal B32List b32_node_to_list(B32Node *node);
|
||||||
internal CharList char_node_to_list(CharNode *node);
|
internal CharList char_node_to_list(CharNode *node);
|
||||||
internal C8List c8_node_to_list(C8Node *node);
|
internal C8List c8_node_to_list(C8Node *node);
|
||||||
@@ -202,179 +201,6 @@ void wapp_str8_list_empty(Str8List *list) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VoidPNode *wapp_void_ptr_list_get(const VoidPList *list, u64 index) {
|
|
||||||
wapp_runtime_assert(index < list->node_count, "`index` is out of bounds");
|
|
||||||
|
|
||||||
VoidPNode *output = NULL;
|
|
||||||
VoidPNode *current = list->first;
|
|
||||||
for (u64 i = 1; i <= index; ++i) {
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
output = current;
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wapp_void_ptr_list_push_front(VoidPList *list, VoidPNode *node) {
|
|
||||||
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
|
|
||||||
|
|
||||||
VoidPList node_list = void_ptr_node_to_list(node);
|
|
||||||
|
|
||||||
if (list->node_count == 0) {
|
|
||||||
*list = node_list;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
list->node_count += node_list.node_count;
|
|
||||||
|
|
||||||
VoidPNode *first = list->first;
|
|
||||||
if (first) {
|
|
||||||
first->prev = node_list.last;
|
|
||||||
}
|
|
||||||
|
|
||||||
list->first = node_list.first;
|
|
||||||
node_list.last->next = first;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wapp_void_ptr_list_push_back(VoidPList *list, VoidPNode *node) {
|
|
||||||
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
|
|
||||||
|
|
||||||
VoidPList node_list = void_ptr_node_to_list(node);
|
|
||||||
|
|
||||||
if (list->node_count == 0) {
|
|
||||||
*list = node_list;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
list->node_count += node_list.node_count;
|
|
||||||
|
|
||||||
VoidPNode *last = list->last;
|
|
||||||
if (last) {
|
|
||||||
last->next = node_list.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
list->last = node_list.last;
|
|
||||||
node_list.first->prev = last;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wapp_void_ptr_list_insert(VoidPList *list, VoidPNode *node, u64 index) {
|
|
||||||
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
|
|
||||||
|
|
||||||
if (index == 0) {
|
|
||||||
wapp_void_ptr_list_push_front(list, node);
|
|
||||||
return;
|
|
||||||
} else if (index == list->node_count) {
|
|
||||||
wapp_void_ptr_list_push_back(list, node);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
VoidPNode *dst_node = wapp_void_ptr_list_get(list, index);
|
|
||||||
if (!dst_node) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
VoidPList node_list = void_ptr_node_to_list(node);
|
|
||||||
|
|
||||||
list->node_count += node_list.node_count;
|
|
||||||
|
|
||||||
VoidPNode *prev = dst_node->prev;
|
|
||||||
|
|
||||||
dst_node->prev = node_list.last;
|
|
||||||
prev->next = node_list.first;
|
|
||||||
|
|
||||||
node_list.first->prev = prev;
|
|
||||||
node_list.last->next = dst_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
VoidPNode *wapp_void_ptr_list_pop_front(VoidPList *list) {
|
|
||||||
wapp_debug_assert(list != NULL, "`list` should not be NULL");
|
|
||||||
|
|
||||||
VoidPNode *output = NULL;
|
|
||||||
|
|
||||||
if (list->node_count == 0) {
|
|
||||||
goto RETURN_VOID_PTR_LIST_POP_FRONT;
|
|
||||||
}
|
|
||||||
|
|
||||||
output = list->first;
|
|
||||||
|
|
||||||
if (list->node_count == 1) {
|
|
||||||
*list = (VoidPList){0};
|
|
||||||
goto RETURN_VOID_PTR_LIST_POP_FRONT;
|
|
||||||
}
|
|
||||||
|
|
||||||
--(list->node_count);
|
|
||||||
list->first = output->next;
|
|
||||||
|
|
||||||
output->prev = output->next = NULL;
|
|
||||||
|
|
||||||
RETURN_VOID_PTR_LIST_POP_FRONT:
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
VoidPNode *wapp_void_ptr_list_pop_back(VoidPList *list) {
|
|
||||||
wapp_debug_assert(list != NULL, "`list` should not be NULL");
|
|
||||||
|
|
||||||
VoidPNode *output = NULL;
|
|
||||||
|
|
||||||
if (list->node_count == 0) {
|
|
||||||
goto RETURN_VOID_PTR_LIST_POP_BACK;
|
|
||||||
}
|
|
||||||
|
|
||||||
output = list->last;
|
|
||||||
|
|
||||||
if (list->node_count == 1) {
|
|
||||||
*list = (VoidPList){0};
|
|
||||||
goto RETURN_VOID_PTR_LIST_POP_BACK;
|
|
||||||
}
|
|
||||||
|
|
||||||
--(list->node_count);
|
|
||||||
list->last = output->prev;
|
|
||||||
|
|
||||||
output->prev = output->next = NULL;
|
|
||||||
|
|
||||||
RETURN_VOID_PTR_LIST_POP_BACK:
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
VoidPNode *wapp_void_ptr_list_remove(VoidPList *list, u64 index) {
|
|
||||||
wapp_debug_assert(list != NULL, "`list` should not be NULL");
|
|
||||||
|
|
||||||
VoidPNode *output = NULL;
|
|
||||||
|
|
||||||
if (index == 0) {
|
|
||||||
output = wapp_void_ptr_list_pop_front(list);
|
|
||||||
goto RETURN_VOID_PTR_LIST_REMOVE;
|
|
||||||
} else if (index == list->node_count) {
|
|
||||||
output = wapp_void_ptr_list_pop_back(list);
|
|
||||||
goto RETURN_VOID_PTR_LIST_REMOVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
output = wapp_void_ptr_list_get(list, index);
|
|
||||||
if (!output) {
|
|
||||||
goto RETURN_VOID_PTR_LIST_REMOVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
output->prev->next = output->next;
|
|
||||||
output->next->prev = output->prev;
|
|
||||||
|
|
||||||
--(list->node_count);
|
|
||||||
|
|
||||||
output->prev = output->next = NULL;
|
|
||||||
|
|
||||||
RETURN_VOID_PTR_LIST_REMOVE:
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wapp_void_ptr_list_empty(VoidPList *list) {
|
|
||||||
wapp_debug_assert(list != NULL, "`list` should not be NULL");
|
|
||||||
|
|
||||||
u64 count = list->node_count;
|
|
||||||
for (u64 i = 0; i < count; ++i) {
|
|
||||||
wapp_void_ptr_list_pop_back(list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
B32Node *wapp_b32_list_get(const B32List *list, u64 index) {
|
B32Node *wapp_b32_list_get(const B32List *list, u64 index) {
|
||||||
wapp_runtime_assert(index < list->node_count, "`index` is out of bounds");
|
wapp_runtime_assert(index < list->node_count, "`index` is out of bounds");
|
||||||
|
|
||||||
@@ -3505,22 +3331,6 @@ internal Str8List str8_node_to_list(Str8Node *node) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal VoidPList void_ptr_node_to_list(VoidPNode *node) {
|
|
||||||
VoidPList output = {.first = node, .last = node, .node_count = 1};
|
|
||||||
|
|
||||||
while (output.first->prev != NULL) {
|
|
||||||
output.first = output.first->prev;
|
|
||||||
++(output.node_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (output.last->next != NULL) {
|
|
||||||
output.last = output.last->next;
|
|
||||||
++(output.node_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal B32List b32_node_to_list(B32Node *node) {
|
internal B32List b32_node_to_list(B32Node *node) {
|
||||||
B32List output = {.first = node, .last = node, .node_count = 1};
|
B32List output = {.first = node, .last = node, .node_count = 1};
|
||||||
|
|
||||||
|
@@ -14,7 +14,6 @@ BEGIN_C_LINKAGE
|
|||||||
|
|
||||||
#ifdef WAPP_PLATFORM_CPP
|
#ifdef WAPP_PLATFORM_CPP
|
||||||
#define wapp_str8_list_node(ITEM_PTR) Str8Node{ITEM_PTR, nullptr, nullptr}
|
#define wapp_str8_list_node(ITEM_PTR) Str8Node{ITEM_PTR, nullptr, nullptr}
|
||||||
#define wapp_void_ptr_list_node(ITEM_PTR) VoidPNode{ITEM_PTR, nullptr, nullptr}
|
|
||||||
#define wapp_b32_list_node(ITEM_PTR) B32Node{ITEM_PTR, nullptr, nullptr}
|
#define wapp_b32_list_node(ITEM_PTR) B32Node{ITEM_PTR, nullptr, nullptr}
|
||||||
#define wapp_char_list_node(ITEM_PTR) CharNode{ITEM_PTR, nullptr, nullptr}
|
#define wapp_char_list_node(ITEM_PTR) CharNode{ITEM_PTR, nullptr, nullptr}
|
||||||
#define wapp_c8_list_node(ITEM_PTR) C8Node{ITEM_PTR, nullptr, nullptr}
|
#define wapp_c8_list_node(ITEM_PTR) C8Node{ITEM_PTR, nullptr, nullptr}
|
||||||
@@ -35,7 +34,6 @@ BEGIN_C_LINKAGE
|
|||||||
#define wapp_uptr_list_node(ITEM_PTR) UptrNode{ITEM_PTR, nullptr, nullptr}
|
#define wapp_uptr_list_node(ITEM_PTR) UptrNode{ITEM_PTR, nullptr, nullptr}
|
||||||
#else
|
#else
|
||||||
#define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR})
|
#define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR})
|
||||||
#define wapp_void_ptr_list_node(ITEM_PTR) ((VoidPNode){.item = ITEM_PTR})
|
|
||||||
#define wapp_b32_list_node(ITEM_PTR) ((B32Node){.item = ITEM_PTR})
|
#define wapp_b32_list_node(ITEM_PTR) ((B32Node){.item = ITEM_PTR})
|
||||||
#define wapp_char_list_node(ITEM_PTR) ((CharNode){.item = ITEM_PTR})
|
#define wapp_char_list_node(ITEM_PTR) ((CharNode){.item = ITEM_PTR})
|
||||||
#define wapp_c8_list_node(ITEM_PTR) ((C8Node){.item = ITEM_PTR})
|
#define wapp_c8_list_node(ITEM_PTR) ((C8Node){.item = ITEM_PTR})
|
||||||
@@ -58,6 +56,20 @@ BEGIN_C_LINKAGE
|
|||||||
|
|
||||||
typedef struct str8 Str8;
|
typedef struct str8 Str8;
|
||||||
|
|
||||||
|
typedef struct GenericNode GenericNode;
|
||||||
|
struct GenericNode {
|
||||||
|
void *item;
|
||||||
|
GenericNode *prev;
|
||||||
|
GenericNode *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct GenericList GenericList;
|
||||||
|
struct GenericList {
|
||||||
|
GenericNode *first;
|
||||||
|
GenericNode *last;
|
||||||
|
u64 node_count;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct Str8Node Str8Node;
|
typedef struct Str8Node Str8Node;
|
||||||
struct Str8Node {
|
struct Str8Node {
|
||||||
Str8 *item;
|
Str8 *item;
|
||||||
@@ -72,20 +84,6 @@ struct Str8List {
|
|||||||
u64 node_count;
|
u64 node_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct VoidPNode VoidPNode;
|
|
||||||
struct VoidPNode {
|
|
||||||
void * *item;
|
|
||||||
VoidPNode *prev;
|
|
||||||
VoidPNode *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct VoidPList VoidPList;
|
|
||||||
struct VoidPList {
|
|
||||||
VoidPNode *first;
|
|
||||||
VoidPNode *last;
|
|
||||||
u64 node_count;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct B32Node B32Node;
|
typedef struct B32Node B32Node;
|
||||||
struct B32Node {
|
struct B32Node {
|
||||||
b32 *item;
|
b32 *item;
|
||||||
@@ -346,14 +344,6 @@ Str8Node *wapp_str8_list_pop_front(Str8List *list);
|
|||||||
Str8Node *wapp_str8_list_pop_back(Str8List *list);
|
Str8Node *wapp_str8_list_pop_back(Str8List *list);
|
||||||
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index);
|
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index);
|
||||||
void wapp_str8_list_empty(Str8List *list);
|
void wapp_str8_list_empty(Str8List *list);
|
||||||
VoidPNode *wapp_void_ptr_list_get(const VoidPList *list, u64 index);
|
|
||||||
void wapp_void_ptr_list_push_front(VoidPList *list, VoidPNode *node);
|
|
||||||
void wapp_void_ptr_list_push_back(VoidPList *list, VoidPNode *node);
|
|
||||||
void wapp_void_ptr_list_insert(VoidPList *list, VoidPNode *node, u64 index);
|
|
||||||
VoidPNode *wapp_void_ptr_list_pop_front(VoidPList *list);
|
|
||||||
VoidPNode *wapp_void_ptr_list_pop_back(VoidPList *list);
|
|
||||||
VoidPNode *wapp_void_ptr_list_remove(VoidPList *list, u64 index);
|
|
||||||
void wapp_void_ptr_list_empty(VoidPList *list);
|
|
||||||
B32Node *wapp_b32_list_get(const B32List *list, u64 index);
|
B32Node *wapp_b32_list_get(const B32List *list, u64 index);
|
||||||
void wapp_b32_list_push_front(B32List *list, B32Node *node);
|
void wapp_b32_list_push_front(B32List *list, B32Node *node);
|
||||||
void wapp_b32_list_push_back(B32List *list, B32Node *node);
|
void wapp_b32_list_push_back(B32List *list, B32Node *node);
|
||||||
|
Reference in New Issue
Block a user