diff --git a/Makefile b/Makefile index 3cfbf67..30e5cd6 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ ifeq ($(CC),gcc) export ASAN_OPTIONS=verify_asan_link_order=0 endif -.PHONY: all clean builddir build-test run-test codegen build-lib full prng testing uuid core containers +.PHONY: all clean builddir build-test run-test codegen build-lib full prng testing uuid core primitives all: clean builddir codegen run-test full @@ -62,5 +62,5 @@ uuid: build-lib core: LIB_SRC = src/core/wapp_core.c core: build-lib -containers: LIB_SRC = src/core/wapp_containers.c -containers: build-lib +primitives: LIB_SRC = src/core/wapp_primitives.c +primitives: build-lib diff --git a/src/containers/array/array.c b/src/containers/array/array.c deleted file mode 100644 index 5492327..0000000 --- a/src/containers/array/array.c +++ /dev/null @@ -1,177 +0,0 @@ -#include "array.h" -#include "../../common/aliases/aliases.h" -#include "../../common/misc/misc_utils.h" -#include "../../core/mem/allocator/mem_allocator.h" -#include - -i32 *wapp_i32_array_get(const I32Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_i32_array_set(I32Array *array, u64 index, i32 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_i32_array_append_capped(I32Array *array, i32 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_i32_array_extend_capped(I32Array *array, const I32Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - i32 *item; - u64 items_to_add = other->count; - for (u64 i = 0; i < items_to_add; ++i) { - item = wapp_i32_array_get(other, i); - if (!item) { - continue; - } - - wapp_i32_array_append_capped(array, *item); - } -} - -void wapp_i32_array_clear(I32Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -i32 wapp_i32_array_pop(I32Array *array) { - if (!array || array->count == 0) { - return (i32){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_i32_array_copy_capped(const I32Array *src, I32Array *dst) { - if (!src || !dst) { - return; - } - - wapp_i32_array_clear(dst); - - i32 *item; - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - for (u64 i = 0; i < to_copy; ++i) { - item = wapp_i32_array_get(src, i); - if (!item) { - continue; - } - - wapp_i32_array_append_capped(dst, *item); - } -} - -I32Array *wapp_i32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(I32Array) + sizeof(i32) * capacity; - I32Array *array = NULL; - - if (!allocator) { - goto RETURN_I32_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_I32_ARRAY_ALLOC; - } - - array->items = (i32 *)((u8 *)array + sizeof(I32Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_I32_ARRAY_ALLOC: - return array; -} - -I32Array *wapp_i32_array_append_alloc(const Allocator *allocator, I32Array *array, i32 item) { - I32Array *output = array; - - if (!allocator || !array) { - goto RETURN_I32_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_i32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_I32_ARRAY_APPEND_ALLOC; - } - wapp_i32_array_copy_capped(array, output); - } - - wapp_i32_array_append_capped(output, item); - -RETURN_I32_ARRAY_APPEND_ALLOC: - return output; -} - -I32Array *wapp_i32_array_extend_alloc(const Allocator *allocator, I32Array *array, const I32Array *other) { - I32Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_I32_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_i32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_I32_ARRAY_EXTEND_ALLOC; - } - wapp_i32_array_copy_capped(array, output); - } - - wapp_i32_array_extend_capped(output, other); - -RETURN_I32_ARRAY_EXTEND_ALLOC: - return output; -} - -I32Array *wapp_i32_array_copy_alloc(const Allocator *allocator, const I32Array *src, I32Array *dst) { - I32Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_I32_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_i32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_I32_ARRAY_COPY_ALLOC; - } - } - - wapp_i32_array_clear(output); - wapp_i32_array_copy_capped(src, output); - -RETURN_I32_ARRAY_COPY_ALLOC: - return output; -} diff --git a/src/containers/array/array.h b/src/containers/array/array.h deleted file mode 100644 index 5f8ec07..0000000 --- a/src/containers/array/array.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef ARRAY_H -#define ARRAY_H - -#include "../../common/aliases/aliases.h" -#include "../../common/misc/misc_utils.h" -#include "../../common/platform/platform.h" -#include "../../core/mem/allocator/mem_allocator.h" - -#ifdef WAPP_PLATFORM_CPP -BEGIN_C_LINKAGE -#endif // !WAPP_PLATFORM_CPP - -typedef struct i32_array I32Array; -struct i32_array { - i32 *items; - u64 count; - u64 capacity; -}; - -#define wapp_i32_array(...) ((I32Array){ \ - .items = (i32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(i32, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2) \ -}) -#define wapp_i32_array_with_capacity(CAPACITY) ((I32Array){.items = (i32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) - -i32 *wapp_i32_array_get(const I32Array *array, u64 index); -void wapp_i32_array_set(I32Array *array, u64 index, i32 item); -void wapp_i32_array_append_capped(I32Array *array, i32 item); -void wapp_i32_array_extend_capped(I32Array *array, const I32Array *other); -void wapp_i32_array_clear(I32Array *array); -i32 wapp_i32_array_pop(I32Array *array); -void wapp_i32_array_copy_capped(const I32Array *src, I32Array *dst); - -I32Array *wapp_i32_array_alloc_capacity(const Allocator *allocator, u64 capacity); -I32Array *wapp_i32_array_append_alloc(const Allocator *allocator, I32Array *array, i32 item); -I32Array *wapp_i32_array_extend_alloc(const Allocator *allocator, I32Array *array, const I32Array *other); -I32Array *wapp_i32_array_copy_alloc(const Allocator *allocator, const I32Array *src, I32Array *dst); - -#ifdef WAPP_PLATFORM_CPP -END_C_LINKAGE -#endif // !WAPP_PLATFORM_CPP - -#endif // !ARRAY_H diff --git a/src/containers/wapp_containers.c b/src/containers/wapp_containers.c deleted file mode 100644 index b9f25a8..0000000 --- a/src/containers/wapp_containers.c +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WAPP_CONTAINERS_C -#define WAPP_CONTAINERS_C - -#include "wapp_containers.h" -#include "array/array.c" -#include "dbl_list/dbl_list.c" - -#endif // !WAPP_CONTAINERS_C diff --git a/src/containers/wapp_containers.h b/src/containers/wapp_containers.h deleted file mode 100644 index eacb239..0000000 --- a/src/containers/wapp_containers.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WAPP_CONTAINERS_H -#define WAPP_CONTAINERS_H - -#include "dbl_list/dbl_list.h" -#include "array/array.h" -#include "../common/wapp_common.h" - -#endif // !WAPP_CONTAINERS_H diff --git a/src/core/mem/arena/mem_arena_allocator.h b/src/core/mem/arena/mem_arena_allocator.h index b4164a6..4bf1e35 100644 --- a/src/core/mem/arena/mem_arena_allocator.h +++ b/src/core/mem/arena/mem_arena_allocator.h @@ -3,7 +3,7 @@ #include "../../../common/aliases/aliases.h" #include "../../../common/platform/platform.h" -#include "../allocator/mem_allocator.h" +#include "../../../primitives/mem_allocator/mem_allocator.h" #include "../../os/mem/mem_os.h" #include diff --git a/src/core/os/cpath/cpath.c b/src/core/os/cpath/cpath.c index d385cc1..aee2e62 100644 --- a/src/core/os/cpath/cpath.c +++ b/src/core/os/cpath/cpath.c @@ -1,10 +1,10 @@ #include "cpath.h" #include "../../../common/aliases/aliases.h" #include "../../../common/misc/misc_utils.h" -#include "../../mem/allocator/mem_allocator.h" #include "../../mem/arena/mem_arena_allocator.h" -#include "../../strings/str8/str8.h" -#include "../../../containers/dbl_list/dbl_list.h" +#include "../../../primitives/dbl_list/dbl_list.h" +#include "../../../primitives/mem_allocator/mem_allocator.h" +#include "../../../primitives/strings/str8/str8.h" #include #include #include diff --git a/src/core/os/cpath/cpath.h b/src/core/os/cpath/cpath.h index ec4ab7b..3e3b9a3 100644 --- a/src/core/os/cpath/cpath.h +++ b/src/core/os/cpath/cpath.h @@ -3,8 +3,8 @@ #include "../../../common/aliases/aliases.h" #include "../../../common/platform/platform.h" -#include "../../mem/allocator/mem_allocator.h" -#include "../../strings/str8/str8.h" +#include "../../../primitives/mem_allocator/mem_allocator.h" +#include "../../../primitives/strings/str8/str8.h" #ifdef WAPP_PLATFORM_CPP BEGIN_C_LINKAGE diff --git a/src/core/os/shell/commander/commander.c b/src/core/os/shell/commander/commander.c index e2ff715..ad83c18 100644 --- a/src/core/os/shell/commander/commander.c +++ b/src/core/os/shell/commander/commander.c @@ -1,12 +1,12 @@ #include "commander.h" #include "commander_output.h" #include "../utils/shell_utils.h" -#include "../../../mem/allocator/mem_allocator.h" #include "../../../mem/arena/mem_arena_allocator.h" -#include "../../../strings/str8/str8.h" -#include "../../../../containers/dbl_list/dbl_list.h" #include "../../../../common/aliases/aliases.h" #include "../../../../common/misc/misc_utils.h" +#include "../../../../primitives/dbl_list/dbl_list.h" +#include "../../../../primitives/mem_allocator/mem_allocator.h" +#include "../../../../primitives/strings/str8/str8.h" #include #include #include diff --git a/src/core/os/shell/commander/commander.h b/src/core/os/shell/commander/commander.h index 3e5e811..5a5e648 100644 --- a/src/core/os/shell/commander/commander.h +++ b/src/core/os/shell/commander/commander.h @@ -4,7 +4,7 @@ #include "commander_output.h" #include "../../../../common/aliases/aliases.h" #include "../../../../common/platform/platform.h" -#include "../../../strings/str8/str8.h" +#include "../../../../primitives/strings/str8/str8.h" #include #include #include diff --git a/src/core/os/shell/termcolour/posix/termcolour_posix.c b/src/core/os/shell/termcolour/posix/termcolour_posix.c index edbf6cf..42524b1 100644 --- a/src/core/os/shell/termcolour/posix/termcolour_posix.c +++ b/src/core/os/shell/termcolour/posix/termcolour_posix.c @@ -1,6 +1,6 @@ #include "../../../../../common/aliases/aliases.h" #include "../../../../../common/platform/platform.h" -#include "../../../../strings/str8/str8.h" +#include "../../../../../primitives/strings/str8/str8.h" #ifdef WAPP_PLATFORM_POSIX diff --git a/src/core/os/shell/termcolour/termcolour.c b/src/core/os/shell/termcolour/termcolour.c index 77ce4a7..e96c04b 100644 --- a/src/core/os/shell/termcolour/termcolour.c +++ b/src/core/os/shell/termcolour/termcolour.c @@ -1,6 +1,6 @@ #include "termcolour.h" #include "terminal_colours.h" -#include "../../../strings/str8/str8.h" +#include "../../../../primitives/strings/str8/str8.h" void wapp_shell_termcolour_print_text(Str8RO *text, TerminalColour colour) { if (colour < WAPP_TERM_COLOUR_FG_BLACK || colour > WAPP_TERM_COLOUR_FG_BR_WHITE) { diff --git a/src/core/os/shell/termcolour/termcolour.h b/src/core/os/shell/termcolour/termcolour.h index 0a9e487..cda7868 100644 --- a/src/core/os/shell/termcolour/termcolour.h +++ b/src/core/os/shell/termcolour/termcolour.h @@ -4,7 +4,7 @@ #include "terminal_colours.h" #include "../../../../common/aliases/aliases.h" #include "../../../../common/platform/platform.h" -#include "../../../strings/str8/str8.h" +#include "../../../../primitives/strings/str8/str8.h" #ifdef WAPP_PLATFORM_CPP BEGIN_C_LINKAGE diff --git a/src/core/os/shell/termcolour/win/termcolour_win.c b/src/core/os/shell/termcolour/win/termcolour_win.c index 5e63b57..d10c7fa 100644 --- a/src/core/os/shell/termcolour/win/termcolour_win.c +++ b/src/core/os/shell/termcolour/win/termcolour_win.c @@ -1,6 +1,6 @@ #include "../../../../../common/aliases/aliases.h" #include "../../../../../common/platform/platform.h" -#include "../../../../strings/str8/str8.h" +#include "../../../../../primitives/strings/str8/str8.h" #ifdef WAPP_PLATFORM_WINDOWS diff --git a/src/core/wapp_core.c b/src/core/wapp_core.c index dfab160..a266f1e 100644 --- a/src/core/wapp_core.c +++ b/src/core/wapp_core.c @@ -2,7 +2,6 @@ #define WAPP_CORE_C #include "wapp_core.h" -#include "strings/str8/str8.c" #include "os/shell/termcolour/posix/termcolour_posix.c" #include "os/shell/termcolour/win/termcolour_win.c" #include "os/shell/termcolour/termcolour.c" @@ -14,9 +13,8 @@ #include "os/mem/win/mem_os_win.c" #include "os/mem/mem_os.c" #include "mem/utils/mem_utils.c" -#include "mem/allocator/mem_allocator.c" #include "mem/arena/mem_arena.c" #include "mem/arena/mem_arena_allocator.c" -#include "../containers/wapp_containers.c" +#include "../primitives/wapp_primitives.c" #endif // !WAPP_CORE_C diff --git a/src/core/wapp_core.h b/src/core/wapp_core.h index e1903a9..885c029 100644 --- a/src/core/wapp_core.h +++ b/src/core/wapp_core.h @@ -1,7 +1,6 @@ #ifndef WAPP_CORE_H #define WAPP_CORE_H -#include "strings/str8/str8.h" #include "os/shell/termcolour/termcolour.h" #include "os/shell/termcolour/terminal_colours.h" #include "os/shell/commander/commander.h" @@ -13,10 +12,9 @@ #include "os/mem/mem_os_ops.h" #include "os/mem/mem_os.h" #include "mem/utils/mem_utils.h" -#include "mem/allocator/mem_allocator.h" #include "mem/arena/mem_arena_allocator.h" #include "mem/arena/mem_arena.h" #include "../common/wapp_common.h" -#include "../containers/wapp_containers.h" +#include "../primitives/wapp_primitives.h" #endif // !WAPP_CORE_H diff --git a/src/containers/dbl_list/dbl_list.c b/src/primitives/dbl_list/dbl_list.c similarity index 100% rename from src/containers/dbl_list/dbl_list.c rename to src/primitives/dbl_list/dbl_list.c diff --git a/src/containers/dbl_list/dbl_list.h b/src/primitives/dbl_list/dbl_list.h similarity index 100% rename from src/containers/dbl_list/dbl_list.h rename to src/primitives/dbl_list/dbl_list.h diff --git a/src/core/mem/allocator/mem_allocator.c b/src/primitives/mem_allocator/mem_allocator.c similarity index 96% rename from src/core/mem/allocator/mem_allocator.c rename to src/primitives/mem_allocator/mem_allocator.c index 134c14c..36a10ab 100644 --- a/src/core/mem/allocator/mem_allocator.c +++ b/src/primitives/mem_allocator/mem_allocator.c @@ -1,5 +1,5 @@ #include "mem_allocator.h" -#include "../../../common/aliases/aliases.h" +#include "../../common/aliases/aliases.h" #include void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) { diff --git a/src/core/mem/allocator/mem_allocator.h b/src/primitives/mem_allocator/mem_allocator.h similarity index 94% rename from src/core/mem/allocator/mem_allocator.h rename to src/primitives/mem_allocator/mem_allocator.h index a0254c8..b9b0993 100644 --- a/src/core/mem/allocator/mem_allocator.h +++ b/src/primitives/mem_allocator/mem_allocator.h @@ -1,8 +1,8 @@ #ifndef MEM_ALLOCATOR_H #define MEM_ALLOCATOR_H -#include "../../../common/aliases/aliases.h" -#include "../../../common/platform/platform.h" +#include "../../common/aliases/aliases.h" +#include "../../common/platform/platform.h" #include #ifdef WAPP_PLATFORM_CPP diff --git a/src/core/strings/str8/str8.c b/src/primitives/strings/str8/str8.c similarity index 99% rename from src/core/strings/str8/str8.c rename to src/primitives/strings/str8/str8.c index 7304c62..9b268e3 100644 --- a/src/core/strings/str8/str8.c +++ b/src/primitives/strings/str8/str8.c @@ -1,6 +1,6 @@ #include "str8.h" #include "../../../common/aliases/aliases.h" -#include "../../mem/allocator/mem_allocator.h" +#include "../../mem_allocator/mem_allocator.h" #include #include #include diff --git a/src/core/strings/str8/str8.h b/src/primitives/strings/str8/str8.h similarity index 97% rename from src/core/strings/str8/str8.h rename to src/primitives/strings/str8/str8.h index 7797316..1b55fd2 100644 --- a/src/core/strings/str8/str8.h +++ b/src/primitives/strings/str8/str8.h @@ -3,8 +3,8 @@ #include "../../../common/aliases/aliases.h" #include "../../../common/platform/platform.h" -#include "../../../containers/dbl_list/dbl_list.h" -#include "../../mem/allocator/mem_allocator.h" +#include "../../../primitives/dbl_list/dbl_list.h" +#include "../../mem_allocator/mem_allocator.h" #include #include diff --git a/src/primitives/wapp_primitives.c b/src/primitives/wapp_primitives.c new file mode 100644 index 0000000..b9885d8 --- /dev/null +++ b/src/primitives/wapp_primitives.c @@ -0,0 +1,10 @@ +#ifndef WAPP_PRIMITIVES_C +#define WAPP_PRIMITIVES_C + +#include "wapp_primitives.h" +#include "array/array.c" +#include "dbl_list/dbl_list.c" +#include "mem_allocator/mem_allocator.c" +#include "strings/str8/str8.c" + +#endif // !WAPP_PRIMITIVES_C diff --git a/src/primitives/wapp_primitives.h b/src/primitives/wapp_primitives.h new file mode 100644 index 0000000..6642c41 --- /dev/null +++ b/src/primitives/wapp_primitives.h @@ -0,0 +1,10 @@ +#ifndef WAPP_PRIMITIVES_H +#define WAPP_PRIMITIVES_H + +#include "dbl_list/dbl_list.h" +#include "array/array.h" +#include "mem_allocator/mem_allocator.h" +#include "strings/str8/str8.h" +#include "../common/wapp_common.h" + +#endif // !WAPP_PRIMITIVES_H diff --git a/src/testing/tester/tester.c b/src/testing/tester/tester.c index 52bfe9b..c00e84c 100644 --- a/src/testing/tester/tester.c +++ b/src/testing/tester/tester.c @@ -1,7 +1,7 @@ #include "tester.h" #include "../../common/aliases/aliases.h" #include "../../core/os/shell/termcolour/termcolour.h" -#include "../../core/strings/str8/str8.h" +#include "../../primitives/strings/str8/str8.h" #include #include #include diff --git a/src/testing/tester/tester.h b/src/testing/tester/tester.h index 3a60d19..4d7a725 100644 --- a/src/testing/tester/tester.h +++ b/src/testing/tester/tester.h @@ -3,7 +3,7 @@ #include "../../common/misc/misc_utils.h" #include "../../common/platform/platform.h" -#include "../../core/strings/str8/str8.h" +#include "../../primitives/strings/str8/str8.h" #include #ifdef WAPP_PLATFORM_CPP diff --git a/src/uuid/uuid.c b/src/uuid/uuid.c index 431615d..c7ccd62 100644 --- a/src/uuid/uuid.c +++ b/src/uuid/uuid.c @@ -1,6 +1,6 @@ #include "uuid.h" #include "../common/aliases/aliases.h" -#include "../core/strings/str8/str8.h" +#include "../primitives/strings/str8/str8.h" #include "../prng/xorshift/xorshift.h" #include #include diff --git a/src/uuid/uuid.h b/src/uuid/uuid.h index edecbd1..cdcdd4b 100644 --- a/src/uuid/uuid.h +++ b/src/uuid/uuid.h @@ -3,7 +3,7 @@ #include "../common/aliases/aliases.h" #include "../common/platform/platform.h" -#include "../core/strings/str8/str8.h" +#include "../primitives/strings/str8/str8.h" #ifdef WAPP_PLATFORM_CPP BEGIN_C_LINKAGE diff --git a/src/wapp.c b/src/wapp.c index 202c27f..54caf06 100644 --- a/src/wapp.c +++ b/src/wapp.c @@ -2,7 +2,7 @@ #define WAPP_C #include "wapp.h" -#include "containers/wapp_containers.c" +#include "primitives/wapp_primitives.c" #include "core/wapp_core.c" #include "prng/wapp_prng.c" #include "uuid/uuid.c" diff --git a/src/wapp.h b/src/wapp.h index c051e1e..d8dbc8b 100644 --- a/src/wapp.h +++ b/src/wapp.h @@ -2,7 +2,7 @@ #define WAPP_H #include "common/wapp_common.h" -#include "containers/wapp_containers.h" +#include "primitives/wapp_primitives.h" #include "core/wapp_core.h" #include "prng/wapp_prng.h" #include "uuid/wapp_uuid.h"