Implement no codegen dedicated array types

This commit is contained in:
2025-12-14 19:06:31 +00:00
parent 056dbbf3d7
commit 0ead85bb2e
9 changed files with 271 additions and 335 deletions

View File

@@ -61,13 +61,13 @@ u64 wapp_file_get_length(File *file) {
return output;
}
u64 wapp_file_read(u8 *dst_byte_array, File *file, u64 item_count) {
wapp_debug_assert(dst_byte_array != NULL && file != NULL,
"`dst_byte_array` and `file` should not be NULL.");
u64 wapp_file_read(Array *dst_buf, File *file, u64 item_count) {
wapp_debug_assert(dst_buf != NULL && file != NULL,
"`dst_buf` and `file` should not be NULL.");
u64 file_length = wapp_file_get_length(file);
u64 item_size = wapp_array_item_size(dst_byte_array);
u64 dst_byte_capacity = wapp_array_capacity(dst_byte_array) * item_size;
u64 item_size = dst_buf->item_size;
u64 dst_byte_capacity = dst_buf->capacity * item_size;
u64 req_byte_count = item_count * item_size;
u64 copy_byte_count = 0;
@@ -77,24 +77,24 @@ u64 wapp_file_read(u8 *dst_byte_array, File *file, u64 item_count) {
copy_byte_count = file_length <= dst_byte_capacity ? file_length : dst_byte_capacity;
}
u64 count = fread(dst_byte_array, sizeof(u8), copy_byte_count, file);
u64 count = fread(dst_buf, sizeof(u8), copy_byte_count, file);
if (ferror(file)) { return 0; }
wapp_array_set_count(dst_byte_array, count / item_size);
dst_buf->count = count / item_size;
return wapp_array_count(dst_byte_array);
return dst_buf->count;
}
u64 wapp_file_write(const u8 *src_byte_array, File *file, u64 item_count) {
wapp_debug_assert(src_byte_array != NULL && file != NULL,
"`src_byte_array` and `file` should not be NULL.");
u64 wapp_file_write(const Array *src_buf, File *file, u64 item_count) {
wapp_debug_assert(src_buf != NULL && file != NULL,
"`src_buf` and `file` should not be NULL.");
u64 item_size = wapp_array_item_size(src_byte_array);
u64 src_byte_count = wapp_array_count(src_byte_array) * item_size;
u64 item_size = src_buf->item_size;
u64 src_byte_count = src_buf->count * item_size;
u64 req_byte_count = item_count * item_size;
u64 to_copy = req_byte_count <= src_byte_count ? req_byte_count : src_byte_count;
return fwrite(src_byte_array, sizeof(u8), to_copy, file);
return fwrite(src_buf, sizeof(u8), to_copy, file);
}
i32 wapp_file_flush(File *file) {