2023-02-28 23:30:14 +00:00
|
|
|
export module turtle.io;
|
|
|
|
|
|
|
|
import coral;
|
|
|
|
import coral.files;
|
|
|
|
|
|
|
|
import turtle;
|
|
|
|
|
|
|
|
export namespace turtle {
|
|
|
|
enum class log_level {
|
|
|
|
notice,
|
|
|
|
warning,
|
|
|
|
error,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct event_loop {
|
|
|
|
bool poll() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-02 20:46:25 +00:00
|
|
|
static int run(coral::slice<char const> const & title, coral::closure<int(event_loop &)> execute) {
|
2023-02-28 23:30:14 +00:00
|
|
|
event_loop loop{title};
|
|
|
|
|
|
|
|
return execute(loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-03-02 20:46:25 +00:00
|
|
|
static constexpr coral::usize title_max = 256;
|
|
|
|
|
|
|
|
coral::u8 title_buffer[256];
|
2023-02-28 23:30:14 +00:00
|
|
|
|
2023-03-02 20:46:25 +00:00
|
|
|
event_loop(coral::slice<char const> const & title) {
|
|
|
|
coral::copy(this->title_buffer, title.sliced(0, coral::min(title.length, title_max)).as_bytes());
|
2023-02-28 23:30:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct system_allocator : public coral::allocator {
|
|
|
|
system_allocator() = default;
|
|
|
|
|
|
|
|
// TODO: implement thread-safety.
|
|
|
|
|
|
|
|
coral::u8 * reallocate(coral::u8 * maybe_allocation, coral::usize requested_size) override {
|
|
|
|
if (maybe_allocation != nullptr) coral::unreachable();
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void deallocate(void * allocation) override {
|
|
|
|
if (allocation != nullptr) coral::unreachable();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|