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:
2025-09-20 13:48:08 +00:00
committed by Abdelrahman Said
parent 09e96f8112
commit 14bd6ce5fd
52 changed files with 3814 additions and 944 deletions

View File

@@ -1,9 +1,8 @@
#include "test_i32_array.h"
#include "wapp.h"
#include <stdbool.h>
TestFuncResult test_i32_array(void) {
bool result;
b32 result;
I32Array array = wapp_i32_array(1, 2, 3, 4, 5, 6, 7);
result = array.count == 7 && array.capacity == 16;
@@ -11,7 +10,7 @@ TestFuncResult test_i32_array(void) {
i32 *item;
u64 count = array.count;
u64 index = 0;
bool running = true;
b32 running = true;
while (running) {
item = wapp_i32_array_get(&array, index);
result = result && item && (*item == (i32)(index + 1));
@@ -24,7 +23,7 @@ TestFuncResult test_i32_array(void) {
}
TestFuncResult test_i32_array_with_capacity(void) {
bool result;
b32 result;
I32Array array = wapp_i32_array_with_capacity(64);
result = array.count == 0 && array.capacity == 64;
@@ -33,14 +32,14 @@ TestFuncResult test_i32_array_with_capacity(void) {
}
TestFuncResult test_i32_array_get(void) {
bool result = true;
b32 result = true;
I32Array array = wapp_i32_array(0, 1, 2, 3, 4, 5, 6, 7, 8);
i32 *item;
u64 count = array.count;
u64 index = 0;
bool running = true;
b32 running = true;
while (running) {
item = wapp_i32_array_get(&array, index);
result = result && item && (*item == (i32)index);
@@ -53,14 +52,14 @@ TestFuncResult test_i32_array_get(void) {
}
TestFuncResult test_i32_array_set(void) {
bool result = true;
b32 result = true;
I32Array array = wapp_i32_array(0, 1, 2, 3, 4, 5, 6, 7, 8);
i32 *item;
u64 count = array.count;
u64 index = 0;
bool running = true;
b32 running = true;
while (running) {
i32 num = (i32)(index * 2);
wapp_i32_array_set(&array, index, &num);
@@ -75,7 +74,7 @@ TestFuncResult test_i32_array_set(void) {
}
TestFuncResult test_i32_array_append_capped(void) {
bool result;
b32 result;
I32Array array = wapp_i32_array_with_capacity(64);
i32 item1 = 10;
@@ -95,7 +94,7 @@ TestFuncResult test_i32_array_append_capped(void) {
}
TestFuncResult test_i32_array_extend_capped(void) {
bool result;
b32 result;
I32Array array1 = wapp_i32_array(1, 2, 3, 4);
I32Array array2 = wapp_i32_array(10, 20);
@@ -110,7 +109,7 @@ TestFuncResult test_i32_array_extend_capped(void) {
}
TestFuncResult test_i32_array_clear(void) {
bool result;
b32 result;
I32Array array = wapp_i32_array(0, 1, 2, 3, 4, 5, 6, 7, 8);
result = array.count == 9;
@@ -123,7 +122,7 @@ TestFuncResult test_i32_array_clear(void) {
}
TestFuncResult test_i32_array_pop(void) {
bool result;
b32 result;
I32Array array1 = wapp_i32_array(0, 1, 2, 3, 4, 5, 6, 7, 8);
I32Array array2 = wapp_i32_array_with_capacity(32);
@@ -137,7 +136,7 @@ TestFuncResult test_i32_array_pop(void) {
}
TestFuncResult test_i32_array_copy_capped(void) {
bool result;
b32 result;
I32Array src = wapp_i32_array(1, 2, 3, 4, 5);
I32Array dst1 = wapp_i32_array(1, 2, 3, 4, 5, 6);
@@ -148,7 +147,7 @@ TestFuncResult test_i32_array_copy_capped(void) {
result = dst1.count == expected_count;
u64 index = 0;
bool running = true;
b32 running = true;
while (running) {
result = result && (*wapp_i32_array_get(&src, index) == *wapp_i32_array_get(&dst1, index));
@@ -173,7 +172,7 @@ TestFuncResult test_i32_array_copy_capped(void) {
}
TestFuncResult test_i32_array_alloc_capacity(void) {
bool result;
b32 result;
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
u64 capacity = 32;
@@ -187,7 +186,7 @@ TestFuncResult test_i32_array_alloc_capacity(void) {
}
TestFuncResult test_i32_array_append_alloc(void) {
bool result;
b32 result;
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
I32Array array1 = wapp_i32_array(1, 2, 3, 4, 5, 6, 7, 8);
@@ -199,7 +198,7 @@ TestFuncResult test_i32_array_append_alloc(void) {
u64 count = 4;
u64 index = 0;
bool running = true;
b32 running = true;
while (running) {
i32 num = (i32)index;
arr_ptr = wapp_i32_array_append_alloc(&allocator, &array2, &num);
@@ -215,7 +214,7 @@ TestFuncResult test_i32_array_append_alloc(void) {
}
TestFuncResult test_i32_array_extend_alloc(void) {
bool result;
b32 result;
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
I32Array array1 = wapp_i32_array(1, 2, 3, 4, 5, 6, 7, 8);
@@ -234,7 +233,7 @@ TestFuncResult test_i32_array_extend_alloc(void) {
}
TestFuncResult test_i32_array_copy_alloc(void) {
bool result;
b32 result;
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
I32Array src = wapp_i32_array(1, 2, 3, 4, 5);
@@ -247,7 +246,7 @@ TestFuncResult test_i32_array_copy_alloc(void) {
result = array_ptr->count == expected_count && array_ptr == &dst1;
u64 index = 0;
bool running = true;
b32 running = true;
while (running) {
result = result && (*wapp_i32_array_get(&src, index) == *wapp_i32_array_get(array_ptr, index));