Application Context Implementation #4
No reviewers
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: kayomn/ona#4
Loading…
Reference in New Issue
No description provided.
Delete Branch "event-loop-dev"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Work goals:
AppContext
).FileAccess
interface that may be offloaded to another thread viaAppContext.schedule
.Path
data structure for accessing the data archive and user directly over the underlying file-system in an opaque manner.Implementation of
GraphicsContext
will come as a separate pull request at a later time. This workload is only focused on implementating the base of the application context for a JavaScript event loop-style work processing that leverages Zig's async-await primitives.WIP: event-loop-devto WIP: Application Context ImplementationSudden realization / consideration.
Rather than rolling a duplicate asynchronous interface for offloading synchronous logic, why not expose a single, generic asynchronous offloading function on
AppContext
.May be worth looking into the Quake Pak file format for inspiration on how to lay out the file format in an efficient manner?
Proposed archive format:
Further considerations have made me realize that the file format would be better served from a simplicity standpoint if entries each encoded their own header data.
This would allow partial upgrades of existing files should changes ever be made to the file spec, and keep the file format simple - as the logic flow for running through the whole archive would be.
Cutting implementation of Oar tool as part of this PR as it has gotten out of hand in size.
Will be resolved as a separate PR.
Minor issues with missing / out-of-date comments but major issue with missing implementation of Oar archive file opening.
@ -0,0 +151,4 @@
///
/// Returns a sliced reference of the raw bytes in `pointer`.
///
/// **Note** that passing a slice will convert it to a byte slice.
Comment needs clarify as it appears slightly misleading / ambiguous in its current wording.
On further thought, having the comment here to begin with only adds confusion.
While slices don't have as trivial of a memory layout as other pointer types, they're still language primitives and should reasonably be treated the same as other pointer kinds.
@ -0,0 +254,4 @@
}
///
/// Searches for the first instance of an `Element` equal to `needle` in `haystack`, returning its
Worth mentioning that it performs linear time, making it O(n) time complexity?
@ -0,0 +279,4 @@
}
///
/// Searches for the first instance of an `Element` sequence equal to the contents of `needle` in
Worth mentioning that this uses linear search?
@ -0,0 +1,60 @@
const std = @import("std");
const testing = @import("./testing.zig");
pub const IntFittingRange = std.math.IntFittingRange;
Warrants
TODO
comment mentioning that this stdlib dependency should be removed in future.@ -0,0 +133,4 @@
///
/// Potential errors that may occur while trying to push one or more elements into a stack.
///
pub const PushError = io.MakeError;
Seeing as
FixedStack
does not depend on any kind of dynamic allocation directly, does it make sense to makePushError
a direct alias ofio.MakeError
?Would it make more sense to use
BufferOverflow
instead ofOutOfMemory
?@ -0,0 +155,4 @@
(stack_address + stack.filled)) return buffer;
// TODO: Investigate ways of freeing if it is the last allocation.
return null;
Reallocation could benefit from the same kind of last-alloc check optimization as deallocation.
May be worth clarifying that in the comment and code structure.
@ -0,0 +134,4 @@
/// Returns the current load factor of `self`, which is derived from the number of capacity
/// that has been filled.
///
pub fn loadFactor(self: Self) f32 {
Since this function is only ever used to check if the load factor is at / beyond its maximum, would it make more sense to replace it with
isMaxLoad(Self) bool
or something like that which meets the requirements of it uses more precisely?@ -0,0 +141,4 @@
///
/// Searches for a value indexed with `key` in `self`.
///
/// The found value is returned or `null` if an key matching `key` failed to be found.
Comment typo:
if any key
instead ofif an key
.@ -0,0 +9,4 @@
return nosuspend await async sys.display(anyerror, run);
}
fn run(app: *sys.App, graphics: *sys.Graphics) anyerror!void {
Missing documentation comment.
@ -0,0 +22,4 @@
///
///
///
pub const Entry = struct {
Missing documentation comment.
@ -0,0 +29,4 @@
///
///
///
pub const FindError = error {
Missing documentation comment.
@ -0,0 +37,4 @@
///
///
///
pub fn find(archive_file: *sys.ReadableFile, entry_path: sys.Path) FindError!Entry {
Missing documentation comment.
@ -0,0 +80,4 @@
///
///
///
pub fn read(entry: Entry, archive_file: *sys.ReadableFile,
Missing documentation comment.
@ -0,0 +91,4 @@
///
///
///
const Header = extern struct {
Missing documentation comment.
@ -0,0 +108,4 @@
///
///
///
const revision_magic = 0;
Missing documentation comment.
@ -0,0 +95,4 @@
///
///
///
pub const ReadableFile = opaque {
Missing documentation comment.
@ -0,0 +99,4 @@
///
///
///
pub fn close(readable_file: *ReadableFile) void {
Missing documentation comment.
@ -0,0 +108,4 @@
///
///
///
pub fn read(readable_file: *ReadableFile, offset: u64, buffer: []u8) FileError!u64 {
Missing documentation comment.
@ -0,0 +149,4 @@
///
///
///
pub fn rwOpsCast(readable_file: *ReadableFile) *ext.SDL_RWops {
Missing documentation comment.
Also, should this be public?
@ -0,0 +156,4 @@
///
///
///
pub fn size(readable_file: *ReadableFile) FileError!u64 {
Missing documentation comment.
@ -0,0 +208,4 @@
/// Returns a [ReadableFile] reference that provides access to the file referenced by `path`or a
/// [OpenError] if it failed.
///
pub fn openRead(file_system: *const FileSystem, path: Path) OpenError!*ReadableFile {
Out of date documentation comment.
@ -0,0 +214,4 @@
const entry = oar.Entry.find(archive_file, path) catch return error.FileNotFound;
_ = entry;
// TODO: Alloc file context.
This should be resolved as part of the PR.
@ -0,0 +348,4 @@
///
///
///
pub fn compare(this: Path, that: Path) isize {
Missing documentation comment.
@ -0,0 +434,4 @@
///
/// Returns a [core.io.Allocator] bound to the underlying system allocator.
///
pub fn allocator() core.io.Allocator {
Unused and out of date.
WIP: Application Context Implementationto Application Context ImplementationTwo remaining tasks before this can be merged in:
Compiler bug causing the build error needs working around - either by patching the error or upgrading Zig to 0.10.0.
The amount of code duplication between the
Allocator
,Writer
, andFileReader
interfaces needs fixing - likely by introducing some sort of generic dynamic dispatch metaprogramming utility into the meta namespace of the core library.Made redundant by #5.
Pull request closed