From 01fe9f2eeab8b54487a4673e74851160adb1718d Mon Sep 17 00:00:00 2001 From: Fabrice Date: Mon, 2 Mar 2026 12:43:25 +0100 Subject: working on array implementation --- src/source.cc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/source.cc') diff --git a/src/source.cc b/src/source.cc index 63fbdea..8129df8 100644 --- a/src/source.cc +++ b/src/source.cc @@ -3,6 +3,7 @@ #include "common.cc" #include "memory.cc" +#include "array.cc" typedef u32 Source_Id; @@ -10,7 +11,7 @@ struct Span { Source_Id id; usize start, end; - Span(Source_Id id, usize start, usize end) : id(id), start(start), end(end) {} + Span(Source_Id id, usize start, usize end) : id(id), start(start), end(end) {} }; struct Buffer { @@ -20,13 +21,14 @@ struct Buffer { const Allocator* allocator; }; -bool buffer_init(Buffer* buffer, const Allocator* allocator, const String* content_in, const String* file_in) { +bool buffer_init(Buffer* buffer, const Allocator* allocator, + const String* content_in, const String* file_in) { String content, file; bool ret = slice_copy(allocator, content_in, &content); - if(unlikely(ret == false)) return false; - + if (unlikely(ret == false)) return false; + ret = slice_copy(allocator, file_in, &file); - if(unlikely(ret == false)) { + if (unlikely(ret == false)) { slice_deallocate(allocator, &content); return false; } @@ -44,9 +46,16 @@ void buffer_deinit(Buffer* buffer) { buffer->allocator = nullptr; } -struct Buffer_Stack { - Link* buffers; - usize nbuffers; +struct Buffer_Manager { + Link* stack; + Array buffers; }; +#define buffer_manager_init(allocator) Buffer_Manager{nullptr, buffer_init(allocator)} + +void buffer_manager_deinit(Buffer_Manager* stack) { + assert(stack != nullptr); + array_deinit(&stack->buffers); +} + #endif -- cgit v1.2.3