Compare commits

..

No commits in common. "011083ab83e958388a623c0f192d35001b165a51" and "75be2316e07660d8546de8ed78951bb3d08e6141" have entirely different histories.

34 changed files with 571 additions and 660 deletions

View File

@ -12,7 +12,7 @@ LIB_OUT = $(BUILD_DIR)/libwapp.so
TEST_OUT = $(BUILD_DIR)/wapptest TEST_OUT = $(BUILD_DIR)/wapptest
ifeq ($(BUILD_TYPE),debug) ifeq ($(BUILD_TYPE),debug)
CFLAGS += -g -fsanitize=address,undefined -DWAPP_DEBUG_ASSERT CFLAGS += -g -fsanitize=address,undefined
else ifeq ($(BUILD_TYPE),release) else ifeq ($(BUILD_TYPE),release)
CFLAGS += -O3 CFLAGS += -O3
else else

View File

@ -46,10 +46,7 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
out_dir.mkdir(parents=True, exist_ok=True) out_dir.mkdir(parents=True, exist_ok=True)
common_includes: List[CInclude] = [ common_includes: List[CInclude] = [
CInclude( CInclude(header="stdbool.h"),
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h", out_dir)).replace("\\", "/"),
local=True,
),
CInclude( CInclude(
header=str(convert_to_relative(WAPP_SRC_ROOT / "primitives" / "mem_allocator" / "mem_allocator.h", out_dir)).replace("\\", "/"), header=str(convert_to_relative(WAPP_SRC_ROOT / "primitives" / "mem_allocator" / "mem_allocator.h", out_dir)).replace("\\", "/"),
local=True, local=True,
@ -77,6 +74,11 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
array_typename="VoidPArray", array_typename="VoidPArray",
) )
continue continue
elif _type == CType.BOOL:
datatypes[_type.value] = ArrayData(
array_typename="BoolArray",
)
continue
type_title = _type.value.title() type_title = _type.value.title()
datatypes[_type.value] = ArrayData( datatypes[_type.value] = ArrayData(
@ -101,10 +103,7 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
includes=[ includes=[
CInclude(header, local=True, same_dir=True), CInclude(header, local=True, same_dir=True),
CInclude(header="stddef.h"), CInclude(header="stddef.h"),
CInclude( CInclude(header="assert.h"),
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "assert" / "assert.h", out_dir)).replace("\\", "/"),
local=True
),
], ],
internal_funcs=[], internal_funcs=[],
funcs=header.funcs funcs=header.funcs

View File

@ -1,4 +1,4 @@
wapp_debug_assert(allocator != NULL, "`array` should not be NULL"); assert(allocator != NULL);
u64 allocation_size = sizeof({ArrayType}) + item_size * capacity; u64 allocation_size = sizeof({ArrayType}) + item_size * capacity;
{ArrayType} *array = wapp_mem_allocator_alloc(allocator, allocation_size); {ArrayType} *array = wapp_mem_allocator_alloc(allocator, allocation_size);

View File

@ -1,4 +1,4 @@
wapp_debug_assert(allocator != NULL && array != NULL, "`allocator` and `array` should not be NULL"); assert(allocator != NULL && array != NULL);
{ArrayType} *output = array; {ArrayType} *output = array;

View File

@ -1,5 +1,4 @@
wapp_debug_assert(array != NULL, "`array` should not be NULL"); assert(array != NULL && array->count < array->capacity);
wapp_runtime_assert(array->count < array->capacity, "`array` is full");
u64 index = (array->count)++; u64 index = (array->count)++;
wapp_{Tlower}_array_set(array, index, item); wapp_{Tlower}_array_set(array, index, item);

View File

@ -1,5 +1,4 @@
wapp_debug_assert(array != NULL, "`array` should not be NULL"); assert(array != NULL && index < array->count);
wapp_runtime_assert(index < array->count, "`index` is out of bounds");
u8 *ptr = (u8 *)(array->items) + (array->item_size * index); u8 *ptr = (u8 *)(array->items) + (array->item_size * index);
return ({T} *)ptr; return ({T} *)ptr;

View File

@ -1,2 +1,2 @@
wapp_debug_assert(array != NULL, "`array` should not be NULL"); assert(array != NULL);
array->count = 0; array->count = 0;

View File

@ -1,4 +1,4 @@
wapp_debug_assert(allocator != NULL && src != NULL && dst != NULL, "`allocator`, `src` and `dst` should not be NULL"); assert(allocator != NULL && src != NULL && dst != NULL);
{ArrayType} *output = dst; {ArrayType} *output = dst;

View File

@ -1,4 +1,4 @@
wapp_debug_assert(src != NULL && dst != NULL, "`src` and `dst` should not be NULL"); assert(src != NULL && dst != NULL);
wapp_{Tlower}_array_clear(dst); wapp_{Tlower}_array_clear(dst);
@ -8,7 +8,7 @@
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity;
u64 item_index = 0; u64 item_index = 0;
b32 running = true; bool running = true;
while (running) {{ while (running) {{
item = wapp_{Tlower}_array_get(src, item_index); item = wapp_{Tlower}_array_get(src, item_index);
++item_index; ++item_index;

View File

@ -1,4 +1,4 @@
wapp_debug_assert(allocator != NULL && array != NULL && other != NULL, "`allocator`, `array` and `other` should not be NULL"); assert(allocator != NULL && array != NULL && other != NULL);
{ArrayType} *output = array; {ArrayType} *output = array;

View File

@ -1,7 +1,7 @@
wapp_debug_assert(array != NULL && other != NULL, "`array` and `other` should not be NULL"); assert(array != NULL && other != NULL);
u64 remaining_capacity = array->capacity - array->count; u64 remaining_capacity = array->capacity - array->count;
wapp_runtime_assert(other->count < remaining_capacity, "`array` does not have enough capacity"); assert(other->count < remaining_capacity);
{T} *item; {T} *item;
@ -9,7 +9,7 @@
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
u64 items_to_add = other->count; u64 items_to_add = other->count;
u64 item_index = 0; u64 item_index = 0;
b32 running = true; bool running = true;
while (running) {{ while (running) {{
item = wapp_{Tlower}_array_get(other, item_index); item = wapp_{Tlower}_array_get(other, item_index);
++item_index; ++item_index;

View File

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

View File

@ -2,7 +2,7 @@ from pathlib import Path
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import List, Dict from typing import List, Dict
from codegen.constants import WAPP_SRC_ROOT from codegen.constants import WAPP_SRC_ROOT
from codegen.utils import load_func_body_from_file, convert_to_relative from codegen.utils import load_func_body_from_file
from codegen.datatypes import ( from codegen.datatypes import (
CDataType, CDataType,
CMacro, CMacro,
@ -49,10 +49,7 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
out_dir.mkdir(parents=True, exist_ok=True) out_dir.mkdir(parents=True, exist_ok=True)
common_includes: List[CInclude] = [ common_includes: List[CInclude] = [
CInclude( CInclude(header="stdbool.h")
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h", out_dir)).replace("\\", "/"),
local=True,
)
] ]
common_decl_types: List[CStruct] = [] common_decl_types: List[CStruct] = []
@ -98,10 +95,6 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
decl_types=[*common_decl_types], decl_types=[*common_decl_types],
includes=[ includes=[
CInclude(header, local=True, same_dir=True), CInclude(header, local=True, same_dir=True),
CInclude(
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "assert" / "assert.h", out_dir)).replace("\\", "/"),
local=True
),
CInclude(header="stddef.h"), CInclude(header="stddef.h"),
CInclude(header="assert.h"), CInclude(header="assert.h"),
], ],

View File

@ -1,4 +1,4 @@
wapp_debug_assert(list != NULL, "`list` should not be NULL"); assert(list != NULL);
u64 count = list->node_count; u64 count = list->node_count;
for (u64 i = 0; i < count; ++i) {{ for (u64 i = 0; i < count; ++i) {{

View File

@ -1,4 +1,4 @@
wapp_runtime_assert(index < list->node_count, "`index` is out of bounds"); assert(index < list->node_count);
{NodeType} *output = NULL; {NodeType} *output = NULL;
{NodeType} *current = list->first; {NodeType} *current = list->first;

View File

@ -1,4 +1,4 @@
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL"); assert(list != NULL && node != NULL && (node->item) != NULL);
if (index == 0) {{ if (index == 0) {{
wapp_{Tlower}_list_push_front(list, node); wapp_{Tlower}_list_push_front(list, node);

View File

@ -1,4 +1,4 @@
wapp_debug_assert(list != NULL, "`list` should not be NULL"); assert(list != NULL);
{NodeType} *output = NULL; {NodeType} *output = NULL;

View File

@ -1,4 +1,4 @@
wapp_debug_assert(list != NULL, "`list` should not be NULL"); assert(list != NULL);
{NodeType} *output = NULL; {NodeType} *output = NULL;

View File

@ -1,4 +1,4 @@
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL"); assert(list != NULL && node != NULL && (node->item) != NULL);
{ListType} node_list = {Tlower}_node_to_list(node); {ListType} node_list = {Tlower}_node_to_list(node);

View File

@ -1,4 +1,4 @@
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL"); assert(list != NULL && node != NULL && (node->item) != NULL);
{ListType} node_list = {Tlower}_node_to_list(node); {ListType} node_list = {Tlower}_node_to_list(node);

View File

@ -1,4 +1,4 @@
wapp_debug_assert(list != NULL, "`list` should not be NULL"); assert(list != NULL);
{NodeType} *output = NULL; {NodeType} *output = NULL;

View File

@ -28,16 +28,6 @@
#define u32 uint32_t #define u32 uint32_t
#define u64 uint64_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 i8 int8_t
#define i16 int16_t #define i16 int16_t
#define i32 int32_t #define i32 int32_t

View File

@ -1,27 +0,0 @@
// vim:fileencoding=utf-8:foldmethod=marker
#include "../aliases/aliases.h"
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#define wapp_static_assert(EXPR, MSG) extern char ASSERTION_FAILED[EXPR ? 1 : -1]
#define wapp_runtime_assert(EXPR, MSG) __wapp_runtime_assert(EXPR, MSG)
#ifdef WAPP_DEBUG_ASSERT
#define wapp_debug_assert(EXPR, MSG) wapp_runtime_assert(EXPR, MSG)
#else
#define wapp_debug_assert(EXPR, MSG)
#endif
#define __wapp_runtime_assert(EXPR, MSG) do { \
if (!(EXPR)) { \
fprintf( \
stderr, \
"%s:%d (In function `%s`): Assertion failed (%" PRIu32 ")\nDiagnostic: %s\n\n", \
__FILE__, __LINE__, __func__, \
EXPR, MSG \
); \
abort(); \
} \
} while(false)

View File

@ -4,7 +4,6 @@
#define WAPP_COMMON_H #define WAPP_COMMON_H
#include "aliases/aliases.h" #include "aliases/aliases.h"
#include "assert/assert.h"
#include "misc/misc_utils.h" #include "misc/misc_utils.h"
#include "platform/platform.h" #include "platform/platform.h"

View File

@ -3,12 +3,12 @@
#include "mem_arena.h" #include "mem_arena.h"
#include "../utils/mem_utils.h" #include "../utils/mem_utils.h"
#include "../../../common/aliases/aliases.h" #include "../../../common/aliases/aliases.h"
#include "../../../common/assert/assert.h"
#include "../../../common/misc/misc_utils.h" #include "../../../common/misc/misc_utils.h"
#include "../../os/mem/mem_os.h" #include "../../os/mem/mem_os.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#ifndef DEFAULT_ALIGNMENT #ifndef DEFAULT_ALIGNMENT
// Why 2 * sizeof(void *) instead of sizeof(void *) // Why 2 * sizeof(void *) instead of sizeof(void *)
@ -66,7 +66,7 @@ void *wapp_mem_arena_alloc(Arena *arena, u64 size) {
} }
void *wapp_mem_arena_alloc_aligned(Arena *arena, u64 size, u64 alignment) { void *wapp_mem_arena_alloc_aligned(Arena *arena, u64 size, u64 alignment) {
wapp_debug_assert(arena != NULL, "`arena` should not be NULL"); assert(arena != NULL);
u8 *alloc_start = arena->offset; u8 *alloc_start = arena->offset;
@ -125,14 +125,14 @@ void *wapp_mem_arena_realloc_aligned(Arena *arena, void *ptr, u64 old_size, u64
} }
void wapp_mem_arena_clear(Arena *arena) { void wapp_mem_arena_clear(Arena *arena) {
wapp_debug_assert(arena != NULL, "`arena` should not be NULL"); assert(arena != NULL);
memset(arena->buf, 0, arena->offset - arena->buf); memset(arena->buf, 0, arena->offset - arena->buf);
arena->offset = arena->buf; arena->offset = arena->buf;
} }
void wapp_mem_arena_destroy(Arena **arena) { void wapp_mem_arena_destroy(Arena **arena) {
wapp_debug_assert(arena != NULL && (*arena) != NULL, "`arena` double pointer is not valid"); assert(arena != NULL && (*arena) != NULL);
Arena *arena_ptr = *arena; Arena *arena_ptr = *arena;
if (arena_ptr->buf) { if (arena_ptr->buf) {

View File

@ -2,15 +2,15 @@
#include "mem_utils.h" #include "mem_utils.h"
#include "../../../common/aliases/aliases.h" #include "../../../common/aliases/aliases.h"
#include "../../../common/assert/assert.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <assert.h>
internal bool is_power_of_two(u64 num) { return (num & (num - 1)) == 0; } internal bool is_power_of_two(u64 num) { return (num & (num - 1)) == 0; }
void *wapp_mem_util_align_forward(void *ptr, u64 alignment) { void *wapp_mem_util_align_forward(void *ptr, u64 alignment) {
wapp_debug_assert(ptr != NULL, "`ptr` should not be NULL"); assert(ptr != NULL);
wapp_runtime_assert(is_power_of_two(alignment), "`alignment` value is not a power of two"); assert(is_power_of_two(alignment));
uptr p = (uptr)ptr; uptr p = (uptr)ptr;
uptr align = (uptr)alignment; uptr align = (uptr)alignment;

File diff suppressed because it is too large Load Diff

View File

@ -5,11 +5,11 @@
#ifndef ARRAY_H #ifndef ARRAY_H
#define ARRAY_H #define ARRAY_H
#include "../../common/aliases/aliases.h"
#include "../mem_allocator/mem_allocator.h" #include "../mem_allocator/mem_allocator.h"
#include "../../common/misc/misc_utils.h" #include "../../common/misc/misc_utils.h"
#include "../../common/aliases/aliases.h" #include "../../common/aliases/aliases.h"
#include "../../common/platform/platform.h" #include "../../common/platform/platform.h"
#include <stdbool.h>
#define wapp_str8_array(...) ((Str8Array){ \ #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__}, \ .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_ptr_array_pop(ARRAY_PTR) : \
(void *){0} \ (void *){0} \
) )
#define wapp_b32_array(...) ((B32Array){ \ #define wapp_bool_array(...) ((BoolArray){ \
.items = (b32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(b32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ .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(b32, __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(b32, __VA_ARGS__) * 2), \ .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(bool, __VA_ARGS__) * 2), \
.item_size = sizeof(b32) \ .item_size = sizeof(bool) \
}) })
#define wapp_b32_array_with_capacity(CAPACITY) ((B32Array){.items = (b32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .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_b32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((B32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(b32))) #define wapp_bool_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((BoolArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(bool)))
#define wapp_b32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \ #define wapp_bool_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_b32_array_pop(ARRAY_PTR) : \ *_bool_array_pop(ARRAY_PTR) : \
(b32){0} \ (bool){0} \
) )
#define wapp_char_array(...) ((CharArray){ \ #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__}, \ .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; u64 item_size;
}; };
typedef struct B32Array B32Array; typedef struct BoolArray BoolArray;
struct B32Array { struct BoolArray {
b32 *items; bool *items;
u64 count; u64 count;
u64 capacity; u64 capacity;
u64 item_size; 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_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); VoidPArray *wapp_void_ptr_array_copy_alloc(const Allocator *allocator, const VoidPArray *src, VoidPArray *dst);
void * *_void_ptr_array_pop(VoidPArray *array); void * *_void_ptr_array_pop(VoidPArray *array);
b32 *wapp_b32_array_get(const B32Array *array, u64 index); bool *wapp_bool_array_get(const BoolArray *array, u64 index);
void wapp_b32_array_set(B32Array *array, u64 index, b32 *item); void wapp_bool_array_set(BoolArray *array, u64 index, bool *item);
void wapp_b32_array_append_capped(B32Array *array, b32 *item); void wapp_bool_array_append_capped(BoolArray *array, bool *item);
void wapp_b32_array_extend_capped(B32Array *array, const B32Array *other); void wapp_bool_array_extend_capped(BoolArray *array, const BoolArray *other);
void wapp_b32_array_clear(B32Array *array); void wapp_bool_array_clear(BoolArray *array);
void wapp_b32_array_copy_capped(const B32Array *src, B32Array *dst); void wapp_bool_array_copy_capped(const BoolArray *src, BoolArray *dst);
B32Array *wapp_b32_array_append_alloc(const Allocator *allocator, B32Array *array, b32 *item); BoolArray *wapp_bool_array_append_alloc(const Allocator *allocator, BoolArray *array, bool *item);
B32Array *wapp_b32_array_extend_alloc(const Allocator *allocator, B32Array *array, const B32Array *other); BoolArray *wapp_bool_array_extend_alloc(const Allocator *allocator, BoolArray *array, const BoolArray *other);
B32Array *wapp_b32_array_copy_alloc(const Allocator *allocator, const B32Array *src, B32Array *dst); BoolArray *wapp_bool_array_copy_alloc(const Allocator *allocator, const BoolArray *src, BoolArray *dst);
b32 *_b32_array_pop(B32Array *array); bool *_bool_array_pop(BoolArray *array);
char *wapp_char_array_get(const CharArray *array, u64 index); 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_set(CharArray *array, u64 index, char *item);
void wapp_char_array_append_capped(CharArray *array, 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 #ifndef DBL_LIST_H
#define DBL_LIST_H #define DBL_LIST_H
#include "../../common/aliases/aliases.h"
#include "../../common/aliases/aliases.h" #include "../../common/aliases/aliases.h"
#include "../../common/platform/platform.h" #include "../../common/platform/platform.h"
#include <stdbool.h>
#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_void_ptr_list_node(ITEM_PTR) ((VoidPNode){.item = ITEM_PTR})
#define wapp_b32_list_node(ITEM_PTR) ((B32Node){.item = ITEM_PTR}) #define wapp_bool_list_node(ITEM_PTR) ((BoolNode){.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})
#define wapp_c16_list_node(ITEM_PTR) ((C16Node){.item = ITEM_PTR}) #define wapp_c16_list_node(ITEM_PTR) ((C16Node){.item = ITEM_PTR})
@ -60,17 +60,17 @@ struct VoidPList {
u64 node_count; u64 node_count;
}; };
typedef struct B32Node B32Node; typedef struct BoolNode BoolNode;
struct B32Node { struct BoolNode {
b32 *item; bool *item;
B32Node *prev; BoolNode *prev;
B32Node *next; BoolNode *next;
}; };
typedef struct B32List B32List; typedef struct BoolList BoolList;
struct B32List { struct BoolList {
B32Node *first; BoolNode *first;
B32Node *last; BoolNode *last;
u64 node_count; 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_pop_back(VoidPList *list);
VoidPNode *wapp_void_ptr_list_remove(VoidPList *list, u64 index); VoidPNode *wapp_void_ptr_list_remove(VoidPList *list, u64 index);
void wapp_void_ptr_list_empty(VoidPList *list); void wapp_void_ptr_list_empty(VoidPList *list);
B32Node *wapp_b32_list_get(const B32List *list, u64 index); BoolNode *wapp_bool_list_get(const BoolList *list, u64 index);
void wapp_b32_list_push_front(B32List *list, B32Node *node); void wapp_bool_list_push_front(BoolList *list, BoolNode *node);
void wapp_b32_list_push_back(B32List *list, B32Node *node); void wapp_bool_list_push_back(BoolList *list, BoolNode *node);
void wapp_b32_list_insert(B32List *list, B32Node *node, u64 index); void wapp_bool_list_insert(BoolList *list, BoolNode *node, u64 index);
B32Node *wapp_b32_list_pop_front(B32List *list); BoolNode *wapp_bool_list_pop_front(BoolList *list);
B32Node *wapp_b32_list_pop_back(B32List *list); BoolNode *wapp_bool_list_pop_back(BoolList *list);
B32Node *wapp_b32_list_remove(B32List *list, u64 index); BoolNode *wapp_bool_list_remove(BoolList *list, u64 index);
void wapp_b32_list_empty(B32List *list); void wapp_bool_list_empty(BoolList *list);
CharNode *wapp_char_list_get(const CharList *list, u64 index); 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_front(CharList *list, CharNode *node);
void wapp_char_list_push_back(CharList *list, CharNode *node); void wapp_char_list_push_back(CharList *list, CharNode *node);

View File

@ -2,27 +2,27 @@
#include "mem_allocator.h" #include "mem_allocator.h"
#include "../../common/aliases/aliases.h" #include "../../common/aliases/aliases.h"
#include "../../common/assert/assert.h"
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) { void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) {
wapp_debug_assert(allocator != NULL && (allocator->alloc) != NULL, "`allocator` and `allocator->alloc` should not be NULL"); assert(allocator != NULL && (allocator->alloc) != NULL);
return allocator->alloc(size, allocator->obj); return allocator->alloc(size, allocator->obj);
} }
void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, u64 alignment) { void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, u64 alignment) {
wapp_debug_assert(allocator != NULL && (allocator->alloc_aligned) != NULL, "`allocator` and `allocator->alloc_aligned` should not be NULL"); assert(allocator != NULL && (allocator->alloc_aligned) != NULL);
return allocator->alloc_aligned(size, alignment, allocator->obj); return allocator->alloc_aligned(size, alignment, allocator->obj);
} }
void *wapp_mem_allocator_realloc(const Allocator *allocator, void *ptr, u64 old_size, u64 new_size) { void *wapp_mem_allocator_realloc(const Allocator *allocator, void *ptr, u64 old_size, u64 new_size) {
wapp_debug_assert(allocator != NULL && (allocator->realloc) != NULL, "`allocator` and `allocator->realloc` should not be NULL"); assert(allocator != NULL && (allocator->realloc) != NULL);
return allocator->realloc(ptr, old_size, new_size, allocator->obj); return allocator->realloc(ptr, old_size, new_size, allocator->obj);
} }
void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr, u64 old_size, void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr, u64 old_size,
u64 new_size, u64 alignment) { u64 new_size, u64 alignment) {
wapp_debug_assert(allocator != NULL && (allocator->realloc_aligned) != NULL, "`allocator` and `allocator->realloc_aligned` should not be NULL"); assert(allocator != NULL && (allocator->realloc_aligned) != NULL);
return allocator->realloc_aligned(ptr, old_size, new_size, alignment, allocator->obj); return allocator->realloc_aligned(ptr, old_size, new_size, alignment, allocator->obj);
} }

View File

@ -2,18 +2,18 @@
#include "str8.h" #include "str8.h"
#include "../../../common/aliases/aliases.h" #include "../../../common/aliases/aliases.h"
#include "../../../common/assert/assert.h"
#include "../../mem_allocator/mem_allocator.h" #include "../../mem_allocator/mem_allocator.h"
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <assert.h>
#define STR8_BUF_ALLOC_SIZE(CAPACITY) (sizeof(Str8) + sizeof(c8) * CAPACITY) #define STR8_BUF_ALLOC_SIZE(CAPACITY) (sizeof(Str8) + sizeof(c8) * CAPACITY)
Str8 *wapp_str8_alloc_buf(const Allocator *allocator, u64 capacity) { Str8 *wapp_str8_alloc_buf(const Allocator *allocator, u64 capacity) {
wapp_debug_assert(allocator != NULL, "`allocator` should not be NULL"); assert(allocator != NULL);
Str8 *str = wapp_mem_allocator_alloc(allocator, STR8_BUF_ALLOC_SIZE(capacity)); Str8 *str = wapp_mem_allocator_alloc(allocator, STR8_BUF_ALLOC_SIZE(capacity));
if (!str) { if (!str) {
@ -29,7 +29,7 @@ RETURN_STR8:
} }
Str8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str) { Str8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str) {
wapp_debug_assert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL"); assert(allocator != NULL && str != NULL);
u64 length = strlen(str); u64 length = strlen(str);
Str8 *output = wapp_str8_alloc_buf(allocator, length * 2); Str8 *output = wapp_str8_alloc_buf(allocator, length * 2);
@ -45,7 +45,7 @@ RETURN_ALLOC_CSTR:
} }
Str8 *wapp_str8_alloc_str8(const Allocator *allocator, Str8RO *str) { Str8 *wapp_str8_alloc_str8(const Allocator *allocator, Str8RO *str) {
wapp_debug_assert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL"); assert(allocator != NULL && str != NULL);
Str8 *output = wapp_str8_alloc_buf(allocator, str->capacity); Str8 *output = wapp_str8_alloc_buf(allocator, str->capacity);
if (!output) { if (!output) {
@ -60,7 +60,7 @@ RETURN_ALLOC_STR8:
} }
Str8 *wapp_str8_alloc_substr(const Allocator *allocator, Str8RO *str, u64 start, u64 end) { Str8 *wapp_str8_alloc_substr(const Allocator *allocator, Str8RO *str, u64 start, u64 end) {
wapp_debug_assert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL"); assert(allocator != NULL && str != NULL);
Str8 *output = NULL; Str8 *output = NULL;
@ -85,7 +85,7 @@ RETURN_ALLOC_SUBSTR:
} }
void wapp_str8_dealloc_buf(const Allocator *allocator, Str8 **str) { void wapp_str8_dealloc_buf(const Allocator *allocator, Str8 **str) {
wapp_debug_assert(allocator != NULL && str != NULL && (*str) != NULL, "Either `allocator` is NULL or `str` is an invalid double pointer"); assert(allocator != NULL && str != NULL && (*str) != NULL);
wapp_mem_allocator_free(allocator, (void **)str, STR8_BUF_ALLOC_SIZE((*str)->capacity)); wapp_mem_allocator_free(allocator, (void **)str, STR8_BUF_ALLOC_SIZE((*str)->capacity));
} }
@ -148,7 +148,7 @@ Str8 wapp_str8_slice(Str8RO *str, u64 start, u64 end) {
} }
Str8 *wapp_str8_alloc_concat(const Allocator *allocator, Str8 *dst, Str8RO *src) { Str8 *wapp_str8_alloc_concat(const Allocator *allocator, Str8 *dst, Str8RO *src) {
wapp_debug_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL"); assert(allocator != NULL && dst != NULL && src != NULL);
Str8 *output = NULL; Str8 *output = NULL;
u64 remaining = dst->capacity - dst->size; u64 remaining = dst->capacity - dst->size;
@ -174,7 +174,7 @@ RETURN_STR8_CONCAT:
} }
void wapp_str8_concat_capped(Str8 *dst, Str8RO *src) { void wapp_str8_concat_capped(Str8 *dst, Str8RO *src) {
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL"); assert(dst != NULL && src != NULL);
u64 remaining = dst->capacity - dst->size; u64 remaining = dst->capacity - dst->size;
u64 to_copy = remaining < src->size ? remaining : src->size; u64 to_copy = remaining < src->size ? remaining : src->size;
@ -184,7 +184,7 @@ void wapp_str8_concat_capped(Str8 *dst, Str8RO *src) {
} }
void wapp_str8_copy_cstr_capped(Str8 *dst, const char *src) { void wapp_str8_copy_cstr_capped(Str8 *dst, const char *src) {
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL"); assert(dst != NULL && src != NULL);
u64 length = strlen(src); u64 length = strlen(src);
u64 to_copy = length <= dst->capacity ? length : dst->capacity; u64 to_copy = length <= dst->capacity ? length : dst->capacity;
@ -195,7 +195,7 @@ void wapp_str8_copy_cstr_capped(Str8 *dst, const char *src) {
} }
void wapp_str8_copy_str8_capped(Str8 *dst, Str8RO *src) { void wapp_str8_copy_str8_capped(Str8 *dst, Str8RO *src) {
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL"); assert(dst != NULL && src != NULL);
u64 to_copy = src->size <= dst->capacity ? src->size : dst->capacity; u64 to_copy = src->size <= dst->capacity ? src->size : dst->capacity;
@ -205,7 +205,7 @@ void wapp_str8_copy_str8_capped(Str8 *dst, Str8RO *src) {
} }
void wapp_str8_copy_to_cstr(char *dst, Str8RO *src, u64 dst_capacity) { void wapp_str8_copy_to_cstr(char *dst, Str8RO *src, u64 dst_capacity) {
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL"); assert(dst != NULL && src != NULL);
u64 to_copy = src->size < dst_capacity ? src->size : dst_capacity - 1; u64 to_copy = src->size < dst_capacity ? src->size : dst_capacity - 1;
@ -214,7 +214,7 @@ void wapp_str8_copy_to_cstr(char *dst, Str8RO *src, u64 dst_capacity) {
} }
void wapp_str8_format(Str8 *dst, const char *format, ...) { void wapp_str8_format(Str8 *dst, const char *format, ...) {
wapp_debug_assert(dst != NULL && format != NULL, "`dst` and `format` should not be NULL"); assert(dst != NULL && format != NULL);
va_list args1; va_list args1;
va_list args2; va_list args2;
@ -276,7 +276,7 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr) {
} }
Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) { Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
wapp_debug_assert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL"); assert(allocator != NULL && str != NULL && delimiter != NULL);
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List)); Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
@ -329,7 +329,7 @@ RETURN_STR8_SPLIT:
} }
Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) { Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
wapp_debug_assert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL"); assert(allocator != NULL && str != NULL && delimiter != NULL);
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List)); Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
@ -379,7 +379,7 @@ RETURN_STR8_SPLIT:
} }
Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter) { Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter) {
wapp_debug_assert(allocator != NULL && list != NULL && delimiter != NULL, "`allocator`, `list` and `delimiter` should not be NULL"); assert(allocator != NULL && list != NULL && delimiter != NULL);
u64 capacity = wapp_str8_list_total_size(list) + (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); Str8 *output = wapp_str8_alloc_buf(allocator, capacity * 2);

View File

@ -2,8 +2,8 @@
#include "xorshift.h" #include "xorshift.h"
#include "../../common/aliases/aliases.h" #include "../../common/aliases/aliases.h"
#include "../../common/assert/assert.h"
#include "../../common/platform/platform.h" #include "../../common/platform/platform.h"
#include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
@ -95,7 +95,7 @@ internal u64 split_mix_64(SplitMix64State *state) {
internal void seed_os_generator(void) { internal void seed_os_generator(void) {
struct timespec ts = {0}; struct timespec ts = {0};
int result = clock_gettime(CLOCK_MONOTONIC_RAW, &ts); int result = clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
wapp_runtime_assert(result == 0, "Invalid seed value"); assert(result == 0);
srand48(ts.tv_nsec); srand48(ts.tv_nsec);
} }
@ -107,7 +107,7 @@ internal u64 generate_random_number(void) {
internal void seed_os_generator(void) { internal void seed_os_generator(void) {
struct timespec ts = {0}; struct timespec ts = {0};
int result = timespec_get(&ts, TIME_UTC); int result = timespec_get(&ts, TIME_UTC);
wapp_runtime_assert(result != 0, "Invalid seed value"); assert(result != 0);
srand(ts.tv_nsec); srand(ts.tv_nsec);
} }
@ -122,7 +122,7 @@ internal u64 generate_random_number(void) {
#else #else
internal void seed_os_generator(void) { internal void seed_os_generator(void) {
time_t result = time(NULL); time_t result = time(NULL);
wapp_runtime_assert(result != (time_t)(-1), "Invalid seed value"); assert(result != (time_t)(-1));
srand(result); srand(result);
} }

View File

@ -2,11 +2,11 @@
#include "uuid.h" #include "uuid.h"
#include "../common/aliases/aliases.h" #include "../common/aliases/aliases.h"
#include "../common/assert/assert.h"
#include "../primitives/strings/str8/str8.h" #include "../primitives/strings/str8/str8.h"
#include "../prng/xorshift/xorshift.h" #include "../prng/xorshift/xorshift.h"
#include <stdbool.h> #include <stdbool.h>
#include <inttypes.h> #include <inttypes.h>
#include <assert.h>
#define UUID_STR_FORMAT ("%.8" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.12" PRIx64) #define UUID_STR_FORMAT ("%.8" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.12" PRIx64)
@ -20,7 +20,7 @@ internal UUID4 generate_uuid4(void);
internal void uuid4_to_uuid(const UUID4* uuid4, UUID *uuid); internal void uuid4_to_uuid(const UUID4* uuid4, UUID *uuid);
UUID *wapp_uuid_init_uuid4(UUID *uuid) { UUID *wapp_uuid_init_uuid4(UUID *uuid) {
wapp_debug_assert(uuid != NULL, "`uuid` should not be NULL"); assert(uuid != NULL);
UUID4 uuid4 = generate_uuid4(); UUID4 uuid4 = generate_uuid4();
uuid4_to_uuid(&uuid4, uuid); uuid4_to_uuid(&uuid4, uuid);