summaryrefslogtreecommitdiff
path: root/src/source.cc
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-03-02 12:43:25 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-03-02 12:43:25 +0100
commit01fe9f2eeab8b54487a4673e74851160adb1718d (patch)
treed95bcb5c81a76660c01fa8434bf59613b6ac7586 /src/source.cc
parentef816e31ba15bbda487298339c5ca88456c31d33 (diff)
working on array implementation
Diffstat (limited to 'src/source.cc')
-rw-r--r--src/source.cc25
1 files changed, 17 insertions, 8 deletions
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<Buffer> 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