Replace bool, true and false with aliases

This commit is contained in:
Abdelrahman Said 2025-08-09 22:38:03 +01:00
parent b8c548ee4b
commit 011083ab83
9 changed files with 560 additions and 515 deletions

View File

@ -77,11 +77,6 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
array_typename="VoidPArray",
)
continue
elif _type == CType.BOOL:
datatypes[_type.value] = ArrayData(
array_typename="BoolArray",
)
continue
type_title = _type.value.title()
datatypes[_type.value] = ArrayData(

View File

@ -8,7 +8,7 @@
// MSVC Spectre mitigation warnings
u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity;
u64 item_index = 0;
bool running = true;
b32 running = true;
while (running) {{
item = wapp_{Tlower}_array_get(src, item_index);
++item_index;

View File

@ -9,7 +9,7 @@
// MSVC Spectre mitigation warnings
u64 items_to_add = other->count;
u64 item_index = 0;
bool running = true;
b32 running = true;
while (running) {{
item = wapp_{Tlower}_array_get(other, item_index);
++item_index;

View File

@ -9,7 +9,7 @@ from codegen.utils import convert_to_relative
class CType(Enum):
VOID = "void"
BOOL = "bool"
BOOL = "b32"
CHAR = "char"
C8 = "c8"
C16 = "c16"

View File

@ -28,6 +28,16 @@
#define u32 uint32_t
#define u64 uint64_t
#define b32 uint32_t
#ifndef false
#define false (b32)0
#endif
#ifndef true
#define true (b32)1
#endif
#define i8 int8_t
#define i16 int16_t
#define i32 int32_t

File diff suppressed because it is too large Load Diff

View File

@ -5,11 +5,11 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "../../common/aliases/aliases.h"
#include "../mem_allocator/mem_allocator.h"
#include "../../common/misc/misc_utils.h"
#include "../../common/aliases/aliases.h"
#include "../../common/platform/platform.h"
#include <stdbool.h>
#define wapp_str8_array(...) ((Str8Array){ \
.items = (Str8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
@ -35,17 +35,17 @@
*_void_ptr_array_pop(ARRAY_PTR) : \
(void *){0} \
)
#define wapp_bool_array(...) ((BoolArray){ \
.items = (bool[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(bool, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(bool, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(bool, __VA_ARGS__) * 2), \
.item_size = sizeof(bool) \
#define wapp_b32_array(...) ((B32Array){ \
.items = (b32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(b32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(b32, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(b32, __VA_ARGS__) * 2), \
.item_size = sizeof(b32) \
})
#define wapp_bool_array_with_capacity(CAPACITY) ((BoolArray){.items = (bool[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(bool)})
#define wapp_bool_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((BoolArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(bool)))
#define wapp_bool_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_bool_array_pop(ARRAY_PTR) : \
(bool){0} \
#define wapp_b32_array_with_capacity(CAPACITY) ((B32Array){.items = (b32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(b32)})
#define wapp_b32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((B32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(b32)))
#define wapp_b32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_b32_array_pop(ARRAY_PTR) : \
(b32){0} \
)
#define wapp_char_array(...) ((CharArray){ \
.items = (char[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(char, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
@ -270,9 +270,9 @@ struct VoidPArray {
u64 item_size;
};
typedef struct BoolArray BoolArray;
struct BoolArray {
bool *items;
typedef struct B32Array B32Array;
struct B32Array {
b32 *items;
u64 count;
u64 capacity;
u64 item_size;
@ -434,16 +434,16 @@ VoidPArray *wapp_void_ptr_array_append_alloc(const Allocator *allocator, VoidPAr
VoidPArray *wapp_void_ptr_array_extend_alloc(const Allocator *allocator, VoidPArray *array, const VoidPArray *other);
VoidPArray *wapp_void_ptr_array_copy_alloc(const Allocator *allocator, const VoidPArray *src, VoidPArray *dst);
void * *_void_ptr_array_pop(VoidPArray *array);
bool *wapp_bool_array_get(const BoolArray *array, u64 index);
void wapp_bool_array_set(BoolArray *array, u64 index, bool *item);
void wapp_bool_array_append_capped(BoolArray *array, bool *item);
void wapp_bool_array_extend_capped(BoolArray *array, const BoolArray *other);
void wapp_bool_array_clear(BoolArray *array);
void wapp_bool_array_copy_capped(const BoolArray *src, BoolArray *dst);
BoolArray *wapp_bool_array_append_alloc(const Allocator *allocator, BoolArray *array, bool *item);
BoolArray *wapp_bool_array_extend_alloc(const Allocator *allocator, BoolArray *array, const BoolArray *other);
BoolArray *wapp_bool_array_copy_alloc(const Allocator *allocator, const BoolArray *src, BoolArray *dst);
bool *_bool_array_pop(BoolArray *array);
b32 *wapp_b32_array_get(const B32Array *array, u64 index);
void wapp_b32_array_set(B32Array *array, u64 index, b32 *item);
void wapp_b32_array_append_capped(B32Array *array, b32 *item);
void wapp_b32_array_extend_capped(B32Array *array, const B32Array *other);
void wapp_b32_array_clear(B32Array *array);
void wapp_b32_array_copy_capped(const B32Array *src, B32Array *dst);
B32Array *wapp_b32_array_append_alloc(const Allocator *allocator, B32Array *array, b32 *item);
B32Array *wapp_b32_array_extend_alloc(const Allocator *allocator, B32Array *array, const B32Array *other);
B32Array *wapp_b32_array_copy_alloc(const Allocator *allocator, const B32Array *src, B32Array *dst);
b32 *_b32_array_pop(B32Array *array);
char *wapp_char_array_get(const CharArray *array, u64 index);
void wapp_char_array_set(CharArray *array, u64 index, char *item);
void wapp_char_array_append_capped(CharArray *array, char *item);

File diff suppressed because it is too large Load Diff

View File

@ -5,13 +5,13 @@
#ifndef DBL_LIST_H
#define DBL_LIST_H
#include "../../common/aliases/aliases.h"
#include "../../common/aliases/aliases.h"
#include "../../common/platform/platform.h"
#include <stdbool.h>
#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_bool_list_node(ITEM_PTR) ((BoolNode){.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_c8_list_node(ITEM_PTR) ((C8Node){.item = ITEM_PTR})
#define wapp_c16_list_node(ITEM_PTR) ((C16Node){.item = ITEM_PTR})
@ -60,17 +60,17 @@ struct VoidPList {
u64 node_count;
};
typedef struct BoolNode BoolNode;
struct BoolNode {
bool *item;
BoolNode *prev;
BoolNode *next;
typedef struct B32Node B32Node;
struct B32Node {
b32 *item;
B32Node *prev;
B32Node *next;
};
typedef struct BoolList BoolList;
struct BoolList {
BoolNode *first;
BoolNode *last;
typedef struct B32List B32List;
struct B32List {
B32Node *first;
B32Node *last;
u64 node_count;
};
@ -328,14 +328,14 @@ 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);
BoolNode *wapp_bool_list_get(const BoolList *list, u64 index);
void wapp_bool_list_push_front(BoolList *list, BoolNode *node);
void wapp_bool_list_push_back(BoolList *list, BoolNode *node);
void wapp_bool_list_insert(BoolList *list, BoolNode *node, u64 index);
BoolNode *wapp_bool_list_pop_front(BoolList *list);
BoolNode *wapp_bool_list_pop_back(BoolList *list);
BoolNode *wapp_bool_list_remove(BoolList *list, u64 index);
void wapp_bool_list_empty(BoolList *list);
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_back(B32List *list, B32Node *node);
void wapp_b32_list_insert(B32List *list, B32Node *node, u64 index);
B32Node *wapp_b32_list_pop_front(B32List *list);
B32Node *wapp_b32_list_pop_back(B32List *list);
B32Node *wapp_b32_list_remove(B32List *list, u64 index);
void wapp_b32_list_empty(B32List *list);
CharNode *wapp_char_list_get(const CharList *list, u64 index);
void wapp_char_list_push_front(CharList *list, CharNode *node);
void wapp_char_list_push_back(CharList *list, CharNode *node);