File utilities and datatype implementation for a C-based code generator (#5)
Co-authored-by: Abdelrahman Said <said.abdelrahman@flawlessai.com> Reviewed-on: #5 Co-authored-by: Abdelrahman <said.abdelrahman89@gmail.com> Co-committed-by: Abdelrahman <said.abdelrahman89@gmail.com>
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
/**
|
||||
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
|
||||
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN.
|
||||
*/
|
||||
|
||||
#ifndef ARRAY_H
|
||||
#define ARRAY_H
|
||||
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../mem_allocator/mem_allocator.h"
|
||||
#include "../../common/misc/misc_utils.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
@@ -15,8 +14,8 @@
|
||||
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_str8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((Str8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(Str8)))
|
||||
#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)))
|
||||
@@ -37,23 +36,6 @@ BEGIN_C_LINKAGE
|
||||
#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{ \
|
||||
@@ -71,6 +53,23 @@ BEGIN_C_LINKAGE
|
||||
*_void_ptr_array_pop(ARRAY_PTR) : \
|
||||
void *{} \
|
||||
)
|
||||
#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_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{ \
|
||||
@@ -378,17 +377,6 @@ BEGIN_C_LINKAGE
|
||||
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__), \
|
||||
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2), \
|
||||
.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_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_str8_array_pop(ARRAY_PTR) : \
|
||||
(Str8){0} \
|
||||
)
|
||||
#define wapp_void_ptr_array(...) ((VoidPArray){ \
|
||||
.items = (void *[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(void *, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
|
||||
.count = wapp_misc_utils_va_args_count(void *, __VA_ARGS__), \
|
||||
@@ -400,6 +388,17 @@ BEGIN_C_LINKAGE
|
||||
*_void_ptr_array_pop(ARRAY_PTR) : \
|
||||
(void *){0} \
|
||||
)
|
||||
#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__), \
|
||||
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2), \
|
||||
.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_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*_str8_array_pop(ARRAY_PTR) : \
|
||||
(Str8){0} \
|
||||
)
|
||||
#define wapp_b32_array(...) ((B32Array){ \
|
||||
.items = (b32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(b32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
|
||||
.count = wapp_misc_utils_va_args_count(b32, __VA_ARGS__), \
|
||||
@@ -602,9 +601,9 @@ BEGIN_C_LINKAGE
|
||||
|
||||
typedef struct str8 Str8;
|
||||
|
||||
typedef struct Str8Array Str8Array;
|
||||
struct Str8Array {
|
||||
Str8 *items;
|
||||
typedef struct GenericArray GenericArray;
|
||||
struct GenericArray {
|
||||
void *items;
|
||||
u64 count;
|
||||
u64 capacity;
|
||||
u64 item_size;
|
||||
@@ -618,6 +617,14 @@ struct VoidPArray {
|
||||
u64 item_size;
|
||||
};
|
||||
|
||||
typedef struct Str8Array Str8Array;
|
||||
struct Str8Array {
|
||||
Str8 *items;
|
||||
u64 count;
|
||||
u64 capacity;
|
||||
u64 item_size;
|
||||
};
|
||||
|
||||
typedef struct B32Array B32Array;
|
||||
struct B32Array {
|
||||
b32 *items;
|
||||
@@ -762,16 +769,6 @@ struct UptrArray {
|
||||
u64 item_size;
|
||||
};
|
||||
|
||||
Str8 *wapp_str8_array_get(const Str8Array *array, u64 index);
|
||||
void wapp_str8_array_set(Str8Array *array, u64 index, Str8 *item);
|
||||
void wapp_str8_array_append_capped(Str8Array *array, Str8 *item);
|
||||
void wapp_str8_array_extend_capped(Str8Array *array, const Str8Array *other);
|
||||
void wapp_str8_array_clear(Str8Array *array);
|
||||
void wapp_str8_array_copy_capped(const Str8Array *src, Str8Array *dst);
|
||||
Str8Array *wapp_str8_array_append_alloc(const Allocator *allocator, Str8Array *array, Str8 *item);
|
||||
Str8Array *wapp_str8_array_extend_alloc(const Allocator *allocator, Str8Array *array, const Str8Array *other);
|
||||
Str8Array *wapp_str8_array_copy_alloc(const Allocator *allocator, const Str8Array *src, Str8Array *dst);
|
||||
Str8 *_str8_array_pop(Str8Array *array);
|
||||
void * *wapp_void_ptr_array_get(const VoidPArray *array, u64 index);
|
||||
void wapp_void_ptr_array_set(VoidPArray *array, u64 index, void * *item);
|
||||
void wapp_void_ptr_array_append_capped(VoidPArray *array, void * *item);
|
||||
@@ -782,6 +779,16 @@ VoidPArray *wapp_void_ptr_array_append_alloc(const Allocator *allocator, VoidPAr
|
||||
VoidPArray *wapp_void_ptr_array_extend_alloc(const Allocator *allocator, VoidPArray *array, const VoidPArray *other);
|
||||
VoidPArray *wapp_void_ptr_array_copy_alloc(const Allocator *allocator, const VoidPArray *src, VoidPArray *dst);
|
||||
void * *_void_ptr_array_pop(VoidPArray *array);
|
||||
Str8 *wapp_str8_array_get(const Str8Array *array, u64 index);
|
||||
void wapp_str8_array_set(Str8Array *array, u64 index, Str8 *item);
|
||||
void wapp_str8_array_append_capped(Str8Array *array, Str8 *item);
|
||||
void wapp_str8_array_extend_capped(Str8Array *array, const Str8Array *other);
|
||||
void wapp_str8_array_clear(Str8Array *array);
|
||||
void wapp_str8_array_copy_capped(const Str8Array *src, Str8Array *dst);
|
||||
Str8Array *wapp_str8_array_append_alloc(const Allocator *allocator, Str8Array *array, Str8 *item);
|
||||
Str8Array *wapp_str8_array_extend_alloc(const Allocator *allocator, Str8Array *array, const Str8Array *other);
|
||||
Str8Array *wapp_str8_array_copy_alloc(const Allocator *allocator, const Str8Array *src, Str8Array *dst);
|
||||
Str8 *_str8_array_pop(Str8Array *array);
|
||||
b32 *wapp_b32_array_get(const B32Array *array, u64 index);
|
||||
void wapp_b32_array_set(B32Array *array, u64 index, b32 *item);
|
||||
void wapp_b32_array_append_capped(B32Array *array, b32 *item);
|
||||
@@ -962,7 +969,7 @@ UptrArray *wapp_uptr_array_append_alloc(const Allocator *allocator, UptrArray *a
|
||||
UptrArray *wapp_uptr_array_extend_alloc(const Allocator *allocator, UptrArray *array, const UptrArray *other);
|
||||
UptrArray *wapp_uptr_array_copy_alloc(const Allocator *allocator, const UptrArray *src, UptrArray *dst);
|
||||
uptr *_uptr_array_pop(UptrArray *array);
|
||||
VoidPArray *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size);
|
||||
GenericArray *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
Reference in New Issue
Block a user