Reintroduce C++ support and add usage tests for C++ (#4)
Reviewed-on: #4 Co-authored-by: Abdelrahman <said.abdelrahman89@gmail.com> Co-committed-by: Abdelrahman <said.abdelrahman89@gmail.com>
This commit is contained in:
@@ -30,13 +30,17 @@
|
||||
|
||||
#define b32 uint32_t
|
||||
|
||||
#ifndef WAPP_PLATFORM_CPP
|
||||
|
||||
#ifndef false
|
||||
#define false (b32)0
|
||||
#endif
|
||||
#endif // !false
|
||||
|
||||
#ifndef true
|
||||
#define true (b32)1
|
||||
#endif
|
||||
#endif // !true
|
||||
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define i8 int8_t
|
||||
#define i16 int16_t
|
||||
@@ -54,4 +58,10 @@
|
||||
#define internal static
|
||||
#define persistent static
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#define class_mem static
|
||||
#define BEGIN_C_LINKAGE extern "C" {
|
||||
#define END_C_LINKAGE }
|
||||
#endif // WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !ALIASES_H
|
||||
|
@@ -1,10 +1,18 @@
|
||||
// vim:fileencoding=utf-8:foldmethod=marker
|
||||
|
||||
#ifndef WAPP_ASSERT_H
|
||||
#define WAPP_ASSERT_H
|
||||
|
||||
#include "../aliases/aliases.h"
|
||||
#include "../platform/platform.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define wapp_static_assert(EXPR, MSG) extern char ASSERTION_FAILED[EXPR ? 1 : -1]
|
||||
#define wapp_runtime_assert(EXPR, MSG) __wapp_runtime_assert(EXPR, MSG)
|
||||
|
||||
@@ -25,3 +33,9 @@
|
||||
abort(); \
|
||||
} \
|
||||
} while(false)
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !WAPP_ASSERT_H
|
||||
|
@@ -5,6 +5,10 @@
|
||||
|
||||
#include "../aliases/aliases.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define KB(SIZE) (SIZE * 1024ull)
|
||||
#define MB(SIZE) (KB(SIZE) * 1024)
|
||||
#define GB(SIZE) (MB(SIZE) * 1024)
|
||||
@@ -34,6 +38,19 @@
|
||||
) + 1 \
|
||||
)
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#define wapp_misc_utils_va_args_count(T, ...) va_args_count<T>(__VA_ARGS__)
|
||||
#else
|
||||
#define wapp_misc_utils_va_args_count(T, ...) (sizeof((T[]){__VA_ARGS__})/sizeof(T))
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
template <typename T, typename... Args>
|
||||
constexpr u64 va_args_count(Args&&...) {
|
||||
return sizeof...(Args);
|
||||
}
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !MISC_UTILS_H
|
||||
|
@@ -61,7 +61,30 @@
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#error "WAPP is a C only library"
|
||||
#define WAPP_PLATFORM_CPP
|
||||
#define WAPP_PLATFORM_CPP_VERSION __cplusplus
|
||||
#define WAPP_PLATFORM_CPP98_VERSION 199711L
|
||||
#define WAPP_PLATFORM_CPP11_VERSION 201103L
|
||||
#define WAPP_PLATFORM_CPP14_VERSION 201402L
|
||||
#define WAPP_PLATFORM_CPP17_VERSION 201703L
|
||||
#define WAPP_PLATFORM_CPP20_VERSION 202002L
|
||||
#define WAPP_PLATFORM_CPP23_VERSION 202302L
|
||||
|
||||
#if WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP98_VERSION
|
||||
#define WAPP_PLATFORM_CPP98
|
||||
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP11_VERSION
|
||||
#define WAPP_PLATFORM_CPP11
|
||||
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP14_VERSION
|
||||
#define WAPP_PLATFORM_CPP14
|
||||
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP17_VERSION
|
||||
#define WAPP_PLATFORM_CPP17
|
||||
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP20_VERSION
|
||||
#define WAPP_PLATFORM_CPP20
|
||||
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP23_VERSION
|
||||
#define WAPP_PLATFORM_CPP23
|
||||
#else
|
||||
#error "Unrecognised C++ version"
|
||||
#endif
|
||||
#else
|
||||
#define WAPP_PLATFORM_C
|
||||
|
||||
|
@@ -8,6 +8,10 @@
|
||||
#include "../../os/mem/mem_os.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
typedef struct arena Arena;
|
||||
|
||||
#define wapp_mem_arena_init(arena_dptr, base_capacity) \
|
||||
@@ -32,4 +36,8 @@ 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_destroy(Arena **arena);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !MEM_ARENA_H
|
||||
|
@@ -9,6 +9,10 @@
|
||||
#include "../../os/mem/mem_os.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define wapp_mem_arena_allocator_init(base_capacity) \
|
||||
(wapp_mem_arena_allocator_init_custom(base_capacity, WAPP_MEM_ALLOC_RESERVE, false))
|
||||
#define wapp_mem_arena_allocator_init_commit(base_capacity) \
|
||||
@@ -33,4 +37,8 @@ Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags
|
||||
void wapp_mem_arena_allocator_clear(Allocator *allocator);
|
||||
void wapp_mem_arena_allocator_destroy(Allocator *allocator);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !MEM_ARENA_ALLOCATOR_H
|
||||
|
@@ -6,6 +6,14 @@
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
void *wapp_mem_util_align_forward(void *ptr, u64 alignment);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !MEM_UTILS_H
|
||||
|
@@ -8,6 +8,10 @@
|
||||
#include "../../../primitives/mem_allocator/mem_allocator.h"
|
||||
#include "../../../primitives/strings/str8/str8.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#ifdef WAPP_PLATFORM_POSIX
|
||||
#define PATH_SEP '/'
|
||||
#elif defined(WAPP_PLATFORM_WINDOWS)
|
||||
@@ -29,4 +33,8 @@ enum {
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts);
|
||||
Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !CPATH_H
|
||||
|
@@ -8,6 +8,10 @@
|
||||
|
||||
#include "mem_os_ops.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#if defined(WAPP_PLATFORM_WINDOWS)
|
||||
#include "win/mem_os_win.h"
|
||||
#elif defined(WAPP_PLATFORM_POSIX)
|
||||
@@ -22,4 +26,8 @@ void wapp_mem_util_free(void *ptr, u64 size);
|
||||
external void *mem_util_allocate(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type);
|
||||
external void mem_util_free(void *ptr, u64 size);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !MEM_OS_H
|
||||
|
@@ -5,6 +5,10 @@
|
||||
|
||||
#include "../../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
typedef enum mem_access {
|
||||
WAPP_MEM_ACCESS_NONE,
|
||||
WAPP_MEM_ACCESS_READ_ONLY,
|
||||
@@ -19,4 +23,8 @@ typedef enum mem_init_type {
|
||||
WAPP_MEM_INIT_INITIALISED,
|
||||
} MemInitType;
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !MEM_OS_OPS_H
|
||||
|
@@ -5,6 +5,10 @@
|
||||
|
||||
#include "../../../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#ifdef WAPP_PLATFORM_POSIX
|
||||
|
||||
#include <sys/mman.h>
|
||||
@@ -24,4 +28,8 @@ typedef enum mem_alloc_flags {
|
||||
|
||||
#endif // !WAPP_PLATFORM_POSIX
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !MEM_OS_POSIX_H
|
||||
|
@@ -5,6 +5,10 @@
|
||||
|
||||
#include "../../../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#ifdef WAPP_PLATFORM_WINDOWS
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
@@ -18,4 +22,8 @@ typedef enum mem_alloc_flags {
|
||||
|
||||
#endif // !WAPP_PLATFORM_WINDOWS
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !MEM_OS_WIN_H
|
||||
|
@@ -11,10 +11,18 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define CMD_NO_EXIT(ERR) ((CMDResult){.exited = false, .exit_code = EXIT_FAILURE, .error = ERR})
|
||||
|
||||
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const Str8List *cmd);
|
||||
|
||||
external CMDError get_output_status(FILE *fp, i32 *status_out);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !COMMANDER_H
|
||||
|
@@ -7,6 +7,10 @@
|
||||
#include "../../../../common/platform/platform.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
typedef enum {
|
||||
SHELL_OUTPUT_DISCARD,
|
||||
SHELL_OUTPUT_PRINT,
|
||||
@@ -34,4 +38,8 @@ struct commander_result {
|
||||
#endif // !WAPP_PLATFORM_WINDOWS
|
||||
};
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !COMMANDER_OUTPUT_H
|
||||
|
@@ -8,9 +8,17 @@
|
||||
#include "../../../../common/platform/platform.h"
|
||||
#include "../../../../primitives/strings/str8/str8.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
void wapp_shell_termcolour_print_text(Str8RO *text, TerminalColour colour);
|
||||
void wapp_shell_termcolour_clear_colour(void);
|
||||
|
||||
external void print_coloured_text(Str8RO *text, TerminalColour colour);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !TERM_COLOUR_H
|
||||
|
@@ -3,8 +3,13 @@
|
||||
#ifndef TERMINAL_COLOURS_H
|
||||
#define TERMINAL_COLOURS_H
|
||||
|
||||
#include "../../../../common/aliases/aliases.h"
|
||||
#include "../../../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
typedef enum {
|
||||
WAPP_TERM_COLOUR_FG_BLACK,
|
||||
WAPP_TERM_COLOUR_FG_RED,
|
||||
@@ -27,4 +32,8 @@ typedef enum {
|
||||
COUNT_TERM_COLOUR,
|
||||
} TerminalColour;
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !TERMINAL_COLOURS_H
|
||||
|
@@ -3,9 +3,14 @@
|
||||
#ifndef SHELL_UTILS_H
|
||||
#define SHELL_UTILS_H
|
||||
|
||||
#include "../../../../common/aliases/aliases.h"
|
||||
#include "../../../../common/platform/platform.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#ifdef WAPP_PLATFORM_WINDOWS
|
||||
#define wapp_shell_utils_popen _popen
|
||||
#define wapp_shell_utils_pclose _pclose
|
||||
@@ -14,4 +19,8 @@
|
||||
#define wapp_shell_utils_pclose pclose
|
||||
#endif /* ifdef WAPP_PLATFORM_WINDOWS */
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !SHELL_UTILS_H
|
||||
|
@@ -11,6 +11,373 @@
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define wapp_str8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((Str8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(Str8)))
|
||||
#define wapp_void_ptr_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((VoidPArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(void *)))
|
||||
#define wapp_b32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((B32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(b32)))
|
||||
#define wapp_char_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((CharArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(char)))
|
||||
#define wapp_c8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((C8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(c8)))
|
||||
#define wapp_c16_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((C16Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(c16)))
|
||||
#define wapp_c32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((C32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(c32)))
|
||||
#define wapp_i8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((I8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(i8)))
|
||||
#define wapp_i16_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((I16Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(i16)))
|
||||
#define wapp_i32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((I32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(i32)))
|
||||
#define wapp_i64_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((I64Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(i64)))
|
||||
#define wapp_u8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((U8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(u8)))
|
||||
#define wapp_u16_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((U16Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(u16)))
|
||||
#define wapp_u32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((U32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(u32)))
|
||||
#define wapp_u64_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((U64Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(u64)))
|
||||
#define wapp_f32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((F32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(f32)))
|
||||
#define wapp_f64_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((F64Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(f64)))
|
||||
#define wapp_f128_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((F128Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(f128)))
|
||||
#define wapp_iptr_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((IptrArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(iptr)))
|
||||
#define wapp_uptr_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((UptrArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(uptr)))
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#define wapp_str8_array(...) ([&]() { \
|
||||
persistent Str8 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return Str8Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(Str8, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2), \
|
||||
sizeof(Str8) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_str8_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent Str8 buf[CAPACITY] = {}; \
|
||||
return Str8Array{buf, 0, CAPACITY, sizeof(Str8)}; \
|
||||
}())
|
||||
#define wapp_str8_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_str8_array_pop(ARRAY_PTR) : \
|
||||
Str8{} \
|
||||
)
|
||||
#define wapp_void_ptr_array(...) ([&]() { \
|
||||
persistent void * buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(void *, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return VoidPArray{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(void *, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(void *, __VA_ARGS__) * 2), \
|
||||
sizeof(void *) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_void_ptr_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent void * buf[CAPACITY] = {}; \
|
||||
return VoidPArray{buf, 0, CAPACITY, sizeof(void *)}; \
|
||||
}())
|
||||
#define wapp_void_ptr_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_void_ptr_array_pop(ARRAY_PTR) : \
|
||||
void *{} \
|
||||
)
|
||||
#define wapp_b32_array(...) ([&]() { \
|
||||
persistent b32 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(b32, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return B32Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(b32, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(b32, __VA_ARGS__) * 2), \
|
||||
sizeof(b32) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_b32_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent b32 buf[CAPACITY] = {}; \
|
||||
return B32Array{buf, 0, CAPACITY, sizeof(b32)}; \
|
||||
}())
|
||||
#define wapp_b32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_b32_array_pop(ARRAY_PTR) : \
|
||||
b32{} \
|
||||
)
|
||||
#define wapp_char_array(...) ([&]() { \
|
||||
persistent char buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(char, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return CharArray{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(char, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(char, __VA_ARGS__) * 2), \
|
||||
sizeof(char) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_char_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent char buf[CAPACITY] = {}; \
|
||||
return CharArray{buf, 0, CAPACITY, sizeof(char)}; \
|
||||
}())
|
||||
#define wapp_char_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_char_array_pop(ARRAY_PTR) : \
|
||||
char{} \
|
||||
)
|
||||
#define wapp_c8_array(...) ([&]() { \
|
||||
persistent c8 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c8, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return C8Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(c8, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c8, __VA_ARGS__) * 2), \
|
||||
sizeof(c8) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_c8_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent c8 buf[CAPACITY] = {}; \
|
||||
return C8Array{buf, 0, CAPACITY, sizeof(c8)}; \
|
||||
}())
|
||||
#define wapp_c8_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_c8_array_pop(ARRAY_PTR) : \
|
||||
c8{} \
|
||||
)
|
||||
#define wapp_c16_array(...) ([&]() { \
|
||||
persistent c16 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c16, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return C16Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(c16, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c16, __VA_ARGS__) * 2), \
|
||||
sizeof(c16) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_c16_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent c16 buf[CAPACITY] = {}; \
|
||||
return C16Array{buf, 0, CAPACITY, sizeof(c16)}; \
|
||||
}())
|
||||
#define wapp_c16_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_c16_array_pop(ARRAY_PTR) : \
|
||||
c16{} \
|
||||
)
|
||||
#define wapp_c32_array(...) ([&]() { \
|
||||
persistent c32 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c32, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return C32Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(c32, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c32, __VA_ARGS__) * 2), \
|
||||
sizeof(c32) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_c32_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent c32 buf[CAPACITY] = {}; \
|
||||
return C32Array{buf, 0, CAPACITY, sizeof(c32)}; \
|
||||
}())
|
||||
#define wapp_c32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_c32_array_pop(ARRAY_PTR) : \
|
||||
c32{} \
|
||||
)
|
||||
#define wapp_i8_array(...) ([&]() { \
|
||||
persistent i8 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i8, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return I8Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(i8, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i8, __VA_ARGS__) * 2), \
|
||||
sizeof(i8) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_i8_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent i8 buf[CAPACITY] = {}; \
|
||||
return I8Array{buf, 0, CAPACITY, sizeof(i8)}; \
|
||||
}())
|
||||
#define wapp_i8_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_i8_array_pop(ARRAY_PTR) : \
|
||||
i8{} \
|
||||
)
|
||||
#define wapp_i16_array(...) ([&]() { \
|
||||
persistent i16 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i16, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return I16Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(i16, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i16, __VA_ARGS__) * 2), \
|
||||
sizeof(i16) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_i16_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent i16 buf[CAPACITY] = {}; \
|
||||
return I16Array{buf, 0, CAPACITY, sizeof(i16)}; \
|
||||
}())
|
||||
#define wapp_i16_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_i16_array_pop(ARRAY_PTR) : \
|
||||
i16{} \
|
||||
)
|
||||
#define wapp_i32_array(...) ([&]() { \
|
||||
persistent i32 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return I32Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(i32, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2), \
|
||||
sizeof(i32) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_i32_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent i32 buf[CAPACITY] = {}; \
|
||||
return I32Array{buf, 0, CAPACITY, sizeof(i32)}; \
|
||||
}())
|
||||
#define wapp_i32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_i32_array_pop(ARRAY_PTR) : \
|
||||
i32{} \
|
||||
)
|
||||
#define wapp_i64_array(...) ([&]() { \
|
||||
persistent i64 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i64, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return I64Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(i64, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i64, __VA_ARGS__) * 2), \
|
||||
sizeof(i64) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_i64_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent i64 buf[CAPACITY] = {}; \
|
||||
return I64Array{buf, 0, CAPACITY, sizeof(i64)}; \
|
||||
}())
|
||||
#define wapp_i64_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_i64_array_pop(ARRAY_PTR) : \
|
||||
i64{} \
|
||||
)
|
||||
#define wapp_u8_array(...) ([&]() { \
|
||||
persistent u8 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u8, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return U8Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(u8, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u8, __VA_ARGS__) * 2), \
|
||||
sizeof(u8) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_u8_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent u8 buf[CAPACITY] = {}; \
|
||||
return U8Array{buf, 0, CAPACITY, sizeof(u8)}; \
|
||||
}())
|
||||
#define wapp_u8_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_u8_array_pop(ARRAY_PTR) : \
|
||||
u8{} \
|
||||
)
|
||||
#define wapp_u16_array(...) ([&]() { \
|
||||
persistent u16 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u16, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return U16Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(u16, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u16, __VA_ARGS__) * 2), \
|
||||
sizeof(u16) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_u16_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent u16 buf[CAPACITY] = {}; \
|
||||
return U16Array{buf, 0, CAPACITY, sizeof(u16)}; \
|
||||
}())
|
||||
#define wapp_u16_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_u16_array_pop(ARRAY_PTR) : \
|
||||
u16{} \
|
||||
)
|
||||
#define wapp_u32_array(...) ([&]() { \
|
||||
persistent u32 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u32, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return U32Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(u32, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u32, __VA_ARGS__) * 2), \
|
||||
sizeof(u32) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_u32_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent u32 buf[CAPACITY] = {}; \
|
||||
return U32Array{buf, 0, CAPACITY, sizeof(u32)}; \
|
||||
}())
|
||||
#define wapp_u32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_u32_array_pop(ARRAY_PTR) : \
|
||||
u32{} \
|
||||
)
|
||||
#define wapp_u64_array(...) ([&]() { \
|
||||
persistent u64 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u64, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return U64Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(u64, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u64, __VA_ARGS__) * 2), \
|
||||
sizeof(u64) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_u64_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent u64 buf[CAPACITY] = {}; \
|
||||
return U64Array{buf, 0, CAPACITY, sizeof(u64)}; \
|
||||
}())
|
||||
#define wapp_u64_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_u64_array_pop(ARRAY_PTR) : \
|
||||
u64{} \
|
||||
)
|
||||
#define wapp_f32_array(...) ([&]() { \
|
||||
persistent f32 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f32, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return F32Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(f32, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f32, __VA_ARGS__) * 2), \
|
||||
sizeof(f32) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_f32_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent f32 buf[CAPACITY] = {}; \
|
||||
return F32Array{buf, 0, CAPACITY, sizeof(f32)}; \
|
||||
}())
|
||||
#define wapp_f32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_f32_array_pop(ARRAY_PTR) : \
|
||||
f32{} \
|
||||
)
|
||||
#define wapp_f64_array(...) ([&]() { \
|
||||
persistent f64 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f64, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return F64Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(f64, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f64, __VA_ARGS__) * 2), \
|
||||
sizeof(f64) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_f64_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent f64 buf[CAPACITY] = {}; \
|
||||
return F64Array{buf, 0, CAPACITY, sizeof(f64)}; \
|
||||
}())
|
||||
#define wapp_f64_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_f64_array_pop(ARRAY_PTR) : \
|
||||
f64{} \
|
||||
)
|
||||
#define wapp_f128_array(...) ([&]() { \
|
||||
persistent f128 buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f128, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return F128Array{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(f128, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f128, __VA_ARGS__) * 2), \
|
||||
sizeof(f128) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_f128_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent f128 buf[CAPACITY] = {}; \
|
||||
return F128Array{buf, 0, CAPACITY, sizeof(f128)}; \
|
||||
}())
|
||||
#define wapp_f128_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_f128_array_pop(ARRAY_PTR) : \
|
||||
f128{} \
|
||||
)
|
||||
#define wapp_iptr_array(...) ([&]() { \
|
||||
persistent iptr buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(iptr, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return IptrArray{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(iptr, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(iptr, __VA_ARGS__) * 2), \
|
||||
sizeof(iptr) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_iptr_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent iptr buf[CAPACITY] = {}; \
|
||||
return IptrArray{buf, 0, CAPACITY, sizeof(iptr)}; \
|
||||
}())
|
||||
#define wapp_iptr_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_iptr_array_pop(ARRAY_PTR) : \
|
||||
iptr{} \
|
||||
)
|
||||
#define wapp_uptr_array(...) ([&]() { \
|
||||
persistent uptr buf[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(uptr, __VA_ARGS__) * 2)] = {__VA_ARGS__}; \
|
||||
return UptrArray{ \
|
||||
buf, \
|
||||
wapp_misc_utils_va_args_count(uptr, __VA_ARGS__), \
|
||||
wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(uptr, __VA_ARGS__) * 2), \
|
||||
sizeof(uptr) \
|
||||
}; \
|
||||
}())
|
||||
#define wapp_uptr_array_with_capacity(CAPACITY) ([&]() { \
|
||||
persistent uptr buf[CAPACITY] = {}; \
|
||||
return UptrArray{buf, 0, CAPACITY, sizeof(uptr)}; \
|
||||
}())
|
||||
#define wapp_uptr_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_uptr_array_pop(ARRAY_PTR) : \
|
||||
uptr{} \
|
||||
)
|
||||
#else
|
||||
#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__}, \
|
||||
.count = wapp_misc_utils_va_args_count(Str8, __VA_ARGS__), \
|
||||
@@ -18,7 +385,6 @@
|
||||
.item_size = sizeof(Str8) \
|
||||
})
|
||||
#define wapp_str8_array_with_capacity(CAPACITY) ((Str8Array){.items = (Str8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(Str8)})
|
||||
#define wapp_str8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((Str8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(Str8)))
|
||||
#define wapp_str8_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_str8_array_pop(ARRAY_PTR) : \
|
||||
(Str8){0} \
|
||||
@@ -30,7 +396,6 @@
|
||||
.item_size = sizeof(void *) \
|
||||
})
|
||||
#define wapp_void_ptr_array_with_capacity(CAPACITY) ((VoidPArray){.items = (void *[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(void *)})
|
||||
#define wapp_void_ptr_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((VoidPArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(void *)))
|
||||
#define wapp_void_ptr_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_void_ptr_array_pop(ARRAY_PTR) : \
|
||||
(void *){0} \
|
||||
@@ -42,7 +407,6 @@
|
||||
.item_size = sizeof(b32) \
|
||||
})
|
||||
#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} \
|
||||
@@ -54,7 +418,6 @@
|
||||
.item_size = sizeof(char) \
|
||||
})
|
||||
#define wapp_char_array_with_capacity(CAPACITY) ((CharArray){.items = (char[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(char)})
|
||||
#define wapp_char_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((CharArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(char)))
|
||||
#define wapp_char_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_char_array_pop(ARRAY_PTR) : \
|
||||
(char){0} \
|
||||
@@ -66,7 +429,6 @@
|
||||
.item_size = sizeof(c8) \
|
||||
})
|
||||
#define wapp_c8_array_with_capacity(CAPACITY) ((C8Array){.items = (c8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(c8)})
|
||||
#define wapp_c8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((C8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(c8)))
|
||||
#define wapp_c8_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_c8_array_pop(ARRAY_PTR) : \
|
||||
(c8){0} \
|
||||
@@ -78,7 +440,6 @@
|
||||
.item_size = sizeof(c16) \
|
||||
})
|
||||
#define wapp_c16_array_with_capacity(CAPACITY) ((C16Array){.items = (c16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(c16)})
|
||||
#define wapp_c16_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((C16Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(c16)))
|
||||
#define wapp_c16_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_c16_array_pop(ARRAY_PTR) : \
|
||||
(c16){0} \
|
||||
@@ -90,7 +451,6 @@
|
||||
.item_size = sizeof(c32) \
|
||||
})
|
||||
#define wapp_c32_array_with_capacity(CAPACITY) ((C32Array){.items = (c32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(c32)})
|
||||
#define wapp_c32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((C32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(c32)))
|
||||
#define wapp_c32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_c32_array_pop(ARRAY_PTR) : \
|
||||
(c32){0} \
|
||||
@@ -102,7 +462,6 @@
|
||||
.item_size = sizeof(i8) \
|
||||
})
|
||||
#define wapp_i8_array_with_capacity(CAPACITY) ((I8Array){.items = (i8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(i8)})
|
||||
#define wapp_i8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((I8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(i8)))
|
||||
#define wapp_i8_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_i8_array_pop(ARRAY_PTR) : \
|
||||
(i8){0} \
|
||||
@@ -114,7 +473,6 @@
|
||||
.item_size = sizeof(i16) \
|
||||
})
|
||||
#define wapp_i16_array_with_capacity(CAPACITY) ((I16Array){.items = (i16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(i16)})
|
||||
#define wapp_i16_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((I16Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(i16)))
|
||||
#define wapp_i16_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_i16_array_pop(ARRAY_PTR) : \
|
||||
(i16){0} \
|
||||
@@ -126,7 +484,6 @@
|
||||
.item_size = sizeof(i32) \
|
||||
})
|
||||
#define wapp_i32_array_with_capacity(CAPACITY) ((I32Array){.items = (i32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(i32)})
|
||||
#define wapp_i32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((I32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(i32)))
|
||||
#define wapp_i32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_i32_array_pop(ARRAY_PTR) : \
|
||||
(i32){0} \
|
||||
@@ -138,7 +495,6 @@
|
||||
.item_size = sizeof(i64) \
|
||||
})
|
||||
#define wapp_i64_array_with_capacity(CAPACITY) ((I64Array){.items = (i64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(i64)})
|
||||
#define wapp_i64_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((I64Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(i64)))
|
||||
#define wapp_i64_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_i64_array_pop(ARRAY_PTR) : \
|
||||
(i64){0} \
|
||||
@@ -150,7 +506,6 @@
|
||||
.item_size = sizeof(u8) \
|
||||
})
|
||||
#define wapp_u8_array_with_capacity(CAPACITY) ((U8Array){.items = (u8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(u8)})
|
||||
#define wapp_u8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((U8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(u8)))
|
||||
#define wapp_u8_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_u8_array_pop(ARRAY_PTR) : \
|
||||
(u8){0} \
|
||||
@@ -162,7 +517,6 @@
|
||||
.item_size = sizeof(u16) \
|
||||
})
|
||||
#define wapp_u16_array_with_capacity(CAPACITY) ((U16Array){.items = (u16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(u16)})
|
||||
#define wapp_u16_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((U16Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(u16)))
|
||||
#define wapp_u16_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_u16_array_pop(ARRAY_PTR) : \
|
||||
(u16){0} \
|
||||
@@ -174,7 +528,6 @@
|
||||
.item_size = sizeof(u32) \
|
||||
})
|
||||
#define wapp_u32_array_with_capacity(CAPACITY) ((U32Array){.items = (u32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(u32)})
|
||||
#define wapp_u32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((U32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(u32)))
|
||||
#define wapp_u32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_u32_array_pop(ARRAY_PTR) : \
|
||||
(u32){0} \
|
||||
@@ -186,7 +539,6 @@
|
||||
.item_size = sizeof(u64) \
|
||||
})
|
||||
#define wapp_u64_array_with_capacity(CAPACITY) ((U64Array){.items = (u64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(u64)})
|
||||
#define wapp_u64_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((U64Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(u64)))
|
||||
#define wapp_u64_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_u64_array_pop(ARRAY_PTR) : \
|
||||
(u64){0} \
|
||||
@@ -198,7 +550,6 @@
|
||||
.item_size = sizeof(f32) \
|
||||
})
|
||||
#define wapp_f32_array_with_capacity(CAPACITY) ((F32Array){.items = (f32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(f32)})
|
||||
#define wapp_f32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((F32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(f32)))
|
||||
#define wapp_f32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_f32_array_pop(ARRAY_PTR) : \
|
||||
(f32){0} \
|
||||
@@ -210,7 +561,6 @@
|
||||
.item_size = sizeof(f64) \
|
||||
})
|
||||
#define wapp_f64_array_with_capacity(CAPACITY) ((F64Array){.items = (f64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(f64)})
|
||||
#define wapp_f64_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((F64Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(f64)))
|
||||
#define wapp_f64_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_f64_array_pop(ARRAY_PTR) : \
|
||||
(f64){0} \
|
||||
@@ -222,7 +572,6 @@
|
||||
.item_size = sizeof(f128) \
|
||||
})
|
||||
#define wapp_f128_array_with_capacity(CAPACITY) ((F128Array){.items = (f128[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(f128)})
|
||||
#define wapp_f128_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((F128Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(f128)))
|
||||
#define wapp_f128_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_f128_array_pop(ARRAY_PTR) : \
|
||||
(f128){0} \
|
||||
@@ -234,7 +583,6 @@
|
||||
.item_size = sizeof(iptr) \
|
||||
})
|
||||
#define wapp_iptr_array_with_capacity(CAPACITY) ((IptrArray){.items = (iptr[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(iptr)})
|
||||
#define wapp_iptr_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((IptrArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(iptr)))
|
||||
#define wapp_iptr_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_iptr_array_pop(ARRAY_PTR) : \
|
||||
(iptr){0} \
|
||||
@@ -246,11 +594,11 @@
|
||||
.item_size = sizeof(uptr) \
|
||||
})
|
||||
#define wapp_uptr_array_with_capacity(CAPACITY) ((UptrArray){.items = (uptr[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(uptr)})
|
||||
#define wapp_uptr_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((UptrArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(uptr)))
|
||||
#define wapp_uptr_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_uptr_array_pop(ARRAY_PTR) : \
|
||||
(uptr){0} \
|
||||
)
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
typedef struct str8 Str8;
|
||||
|
||||
@@ -616,4 +964,8 @@ UptrArray *wapp_uptr_array_copy_alloc(const Allocator *allocator, const UptrArra
|
||||
uptr *_uptr_array_pop(UptrArray *array);
|
||||
VoidPArray *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !ARRAY_H
|
||||
|
@@ -9,6 +9,32 @@
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#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_char_list_node(ITEM_PTR) CharNode{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_c8_list_node(ITEM_PTR) C8Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_c16_list_node(ITEM_PTR) C16Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_c32_list_node(ITEM_PTR) C32Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_i8_list_node(ITEM_PTR) I8Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_i16_list_node(ITEM_PTR) I16Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_i32_list_node(ITEM_PTR) I32Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_i64_list_node(ITEM_PTR) I64Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_u8_list_node(ITEM_PTR) U8Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_u16_list_node(ITEM_PTR) U16Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_u32_list_node(ITEM_PTR) U32Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_u64_list_node(ITEM_PTR) U64Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_f32_list_node(ITEM_PTR) F32Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_f64_list_node(ITEM_PTR) F64Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_f128_list_node(ITEM_PTR) F128Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_iptr_list_node(ITEM_PTR) IptrNode{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_uptr_list_node(ITEM_PTR) UptrNode{ITEM_PTR, nullptr, nullptr}
|
||||
#else
|
||||
#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})
|
||||
@@ -29,6 +55,7 @@
|
||||
#define wapp_f128_list_node(ITEM_PTR) ((F128Node){.item = ITEM_PTR})
|
||||
#define wapp_iptr_list_node(ITEM_PTR) ((IptrNode){.item = ITEM_PTR})
|
||||
#define wapp_uptr_list_node(ITEM_PTR) ((UptrNode){.item = ITEM_PTR})
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
typedef struct str8 Str8;
|
||||
|
||||
@@ -473,4 +500,8 @@ UptrNode *wapp_uptr_list_pop_back(UptrList *list);
|
||||
UptrNode *wapp_uptr_list_remove(UptrList *list, u64 index);
|
||||
void wapp_uptr_list_empty(UptrList *list);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !DBL_LIST_H
|
||||
|
@@ -7,6 +7,10 @@
|
||||
#include "../../common/platform/platform.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
typedef void *(MemAllocFunc)(u64 size, void *alloc_obj);
|
||||
typedef void *(MemAllocAlignedFunc)(u64 size, u64 alignment, void *alloc_obj);
|
||||
typedef void *(MemReallocFunc)(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
|
||||
@@ -23,7 +27,14 @@ struct allocator {
|
||||
MemFreeFunc *free;
|
||||
};
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#define wapp_mem_allocator_invalid(ALLOCATOR) ([&]() { \
|
||||
Allocator alloc{}; \
|
||||
return memcmp(ALLOCATOR, &alloc, sizeof(Allocator)) == 0; \
|
||||
}())
|
||||
#else
|
||||
#define wapp_mem_allocator_invalid(ALLOCATOR) (memcmp(ALLOCATOR, &((Allocator){0}), sizeof(Allocator)) == 0)
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size);
|
||||
void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, u64 alignment);
|
||||
@@ -32,4 +43,8 @@ void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr,
|
||||
u64 new_size, u64 alignment);
|
||||
void wapp_mem_allocator_free(const Allocator *allocator, void **ptr, u64 size);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !MEM_ALLOCATOR_H
|
||||
|
@@ -28,6 +28,15 @@ RETURN_STR8:
|
||||
return str;
|
||||
}
|
||||
|
||||
Str8 *wapp_str8_alloc_and_fill_buf(const Allocator *allocator, u64 capacity) {
|
||||
Str8 *out = wapp_str8_alloc_buf(allocator, capacity);
|
||||
if (out) {
|
||||
memset(out->buf, 0, capacity);
|
||||
out->size = capacity;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
|
@@ -4,12 +4,17 @@
|
||||
#define STR8_H
|
||||
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/assert/assert.h"
|
||||
#include "../../../common/platform/platform.h"
|
||||
#include "../../../primitives/dbl_list/dbl_list.h"
|
||||
#include "../../mem_allocator/mem_allocator.h"
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
typedef struct str8 Str8;
|
||||
struct str8 {
|
||||
u64 capacity;
|
||||
@@ -28,6 +33,25 @@ typedef const Str8 Str8RO;
|
||||
/**
|
||||
* Str8 stack buffers
|
||||
*/
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
// Uses a lambda to achieve the same behaviour achieved by the C macro
|
||||
#define wapp_str8_buf(CAPACITY) ([&](){ \
|
||||
persistent c8 buf[CAPACITY] = {}; \
|
||||
memset(buf, 0, CAPACITY); \
|
||||
return Str8{CAPACITY, 0, buf}; \
|
||||
}())
|
||||
|
||||
// Uses a lambda to achieve the same behaviour achieved by the C macro
|
||||
#define wapp_str8_lit(STRING) ([&]() { \
|
||||
persistent c8 buf[sizeof(STRING) * 2] = {}; \
|
||||
memcpy(buf, STRING, sizeof(STRING)); \
|
||||
return Str8{(sizeof(STRING) - 1) * 2, sizeof(STRING) - 1, buf}; \
|
||||
}())
|
||||
|
||||
#define wapp_str8_lit_ro(STRING) Str8RO{sizeof(STRING) - 1, sizeof(STRING) - 1, (c8 *)STRING}
|
||||
#define wapp_str8_lit_ro_initialiser_list(STRING) {sizeof(STRING) - 1, sizeof(STRING) - 1, (c8 *)STRING}
|
||||
#else
|
||||
#define wapp_str8_buf(CAPACITY) ((Str8){.capacity = CAPACITY, .size = 0, .buf = (c8[CAPACITY]){0}})
|
||||
|
||||
// Utilises the fact that memcpy returns pointer to dest buffer and that getting
|
||||
@@ -44,11 +68,13 @@ typedef const Str8 Str8RO;
|
||||
#define wapp_str8_lit_ro_initialiser_list(STRING) {.capacity = sizeof(STRING) - 1, \
|
||||
.size = sizeof(STRING) - 1, \
|
||||
.buf = (c8 *)STRING}
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
/**
|
||||
* Str8 allocated buffers
|
||||
*/
|
||||
Str8 *wapp_str8_alloc_buf(const Allocator *allocator, u64 capacity);
|
||||
Str8 *wapp_str8_alloc_and_fill_buf(const Allocator *allocator, u64 capacity);
|
||||
Str8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str);
|
||||
Str8 *wapp_str8_alloc_str8(const Allocator *allocator, Str8RO *str);
|
||||
Str8 *wapp_str8_alloc_substr(const Allocator *allocator, Str8RO *str, u64 start, u64 end);
|
||||
@@ -90,8 +116,23 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8R
|
||||
/**
|
||||
* Str8 list utilities
|
||||
*/
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#define wapp_str8_node_from_cstr(STRING) wapp_str8_list_node([&]() { \
|
||||
persistent Str8 str = wapp_str8_lit(STRING); \
|
||||
return &str; \
|
||||
}())
|
||||
#define wapp_str8_node_from_str8(STRING) wapp_str8_list_node([&]() { \
|
||||
persistent Str8 str = STRING; \
|
||||
return &str; \
|
||||
}())
|
||||
#else
|
||||
#define wapp_str8_node_from_cstr(STRING) wapp_str8_list_node(&wapp_str8_lit(STRING))
|
||||
#define wapp_str8_node_from_str8(STRING) wapp_str8_list_node(&(STRING))
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
u64 wapp_str8_list_total_size(const Str8List *list);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !STR8_H
|
||||
|
@@ -6,6 +6,10 @@
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
typedef struct xor_256_state XOR256State;
|
||||
struct xor_256_state {
|
||||
u64 x;
|
||||
@@ -19,4 +23,8 @@ u64 wapp_prng_xorshift_256(XOR256State *state);
|
||||
u64 wapp_prng_xorshift_256ss(XOR256State *state);
|
||||
u64 wapp_prng_xorshift_256p(XOR256State *state);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !XORSHIFT_H
|
||||
|
@@ -8,7 +8,16 @@
|
||||
#include "../../primitives/strings/str8/str8.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#define wapp_tester_result(PASSED) (TestFuncResult{wapp_str8_lit_ro(__func__), PASSED})
|
||||
#else
|
||||
#define wapp_tester_result(PASSED) ((TestFuncResult){.name = wapp_str8_lit_ro(__func__), .passed = PASSED})
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define wapp_tester_run_tests(...) run_tests(__VA_ARGS__, NULL)
|
||||
|
||||
typedef struct test_func_result TestFuncResult;
|
||||
@@ -25,4 +34,8 @@ typedef TestFuncResult(TestFunc)(void);
|
||||
|
||||
void run_tests(TestFunc *func1, ...);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !TESTER_H
|
||||
|
@@ -7,6 +7,10 @@
|
||||
#include "../common/platform/platform.h"
|
||||
#include "../primitives/strings/str8/str8.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define UUID_BUF_LENGTH 48
|
||||
#define WAPP_UUID_SPEC WAPP_STR8_SPEC
|
||||
#define wapp_uuid_varg(UUID) wapp_str8_varg((UUID).uuid)
|
||||
@@ -26,4 +30,8 @@ struct uuid {
|
||||
// Fails when passed a NULL pointer.
|
||||
UUID *wapp_uuid_init_uuid4(UUID *uuid);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !UUID_H
|
||||
|
Reference in New Issue
Block a user