From: Brendan Hansen Date: Thu, 22 Apr 2021 20:03:35 +0000 (-0500) Subject: removed some unneeded enum member look ups X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=99026f9536911e36a6f72d99146ce50ed627efce;p=onyx.git removed some unneeded enum member look ups --- diff --git a/bin/onyx b/bin/onyx index 4e721af4..0204302c 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/alloc/fixed.onyx b/core/alloc/fixed.onyx index 4019da8c..2ab51ee0 100644 --- a/core/alloc/fixed.onyx +++ b/core/alloc/fixed.onyx @@ -19,7 +19,7 @@ FixedAllocatorData :: struct { fixed_allocator_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: u32, oldptr: rawptr) -> rawptr { fa_data := cast(^FixedAllocatorData) data; - if aa != AllocationAction.Alloc do return null; + if aa != .Alloc do return null; if size > fa_data.size do return null; return fa_data.ptr; diff --git a/core/alloc/heap.onyx b/core/alloc/heap.onyx index cfe0e3fd..be78fd39 100644 --- a/core/alloc/heap.onyx +++ b/core/alloc/heap.onyx @@ -125,9 +125,9 @@ heap_resize :: (ptr: rawptr, new_size: u32, align: u32) -> rawptr { #private_file heap_alloc_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: u32, oldptr: rawptr) -> rawptr { - if aa == AllocationAction.Alloc do return heap_alloc(size, align); - if aa == AllocationAction.Resize do return heap_resize(oldptr, size, align); - if aa == AllocationAction.Free { + if aa == .Alloc do return heap_alloc(size, align); + if aa == .Resize do return heap_resize(oldptr, size, align); + if aa == .Free { heap_free(oldptr); return null; } diff --git a/core/alloc/pool.onyx b/core/alloc/pool.onyx index 2a52d121..b32c29bd 100644 --- a/core/alloc/pool.onyx +++ b/core/alloc/pool.onyx @@ -19,17 +19,17 @@ PoolAllocator :: struct (Elem: type_expr) { #private_file pool_allocator_proc :: (pool: ^PoolAllocator($Elem), aa: AllocationAction, size: u32, align: u32, oldptr: rawptr) -> rawptr { switch aa { - case AllocationAction.Alloc { + case .Alloc { assert(size == sizeof Elem, "Allocating wrong size from pool allocator."); return pool_alloc(pool); } - case AllocationAction.Resize { + case .Resize { assert(false, "Cannot resize in a pool allocator!"); return null; } - case AllocationAction.Free { + case .Free { pool_free(pool, ~~ oldptr); return null; } @@ -67,7 +67,7 @@ make :: (buffer: [] $Elem) -> PoolAllocator(Elem) { *(cast(^rawptr) ^buffer[buffer.count - 1]) = null; - return .{ + return .{ buffer = buffer, first_free = ^buffer[0], }; diff --git a/core/alloc/ring.onyx b/core/alloc/ring.onyx index 1f11bd2a..e9ff8b84 100644 --- a/core/alloc/ring.onyx +++ b/core/alloc/ring.onyx @@ -20,7 +20,7 @@ RingState :: struct { ring_alloc_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: u32, oldptr: rawptr) -> rawptr { ss := cast(^RingState) data; - if aa == AllocationAction.Alloc { + if aa == .Alloc { retval := null; rem := ss.size - cast(u32) ss.curr_ptr + cast(u32) ss.base_ptr; @@ -39,7 +39,7 @@ ring_alloc_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: u32, o } make :: (buffer: rawptr, length: u32) -> RingState { - return RingState.{ + return .{ base_ptr = buffer, curr_ptr = buffer, size = length, @@ -47,7 +47,7 @@ make :: (buffer: rawptr, length: u32) -> RingState { } make_allocator :: (rs: ^RingState) -> Allocator { - return Allocator.{ + return .{ func = ring_alloc_proc, data = rs, }; diff --git a/core/io/file.onyx b/core/io/file.onyx index 640ea141..454e9f5a 100644 --- a/core/io/file.onyx +++ b/core/io/file.onyx @@ -26,7 +26,7 @@ OpenMode :: enum { File :: struct { fd : FileDescriptor; - mode : OpenMode = OpenMode.Invalid; + mode : OpenMode = .Invalid; rights : Rights = ~~ 0; flags : FDFlags = ~~ 0; } @@ -70,18 +70,18 @@ file_open :: (path: str, mode := OpenMode.Read, flags := FDFlags.Sync) -> (File, fd_flags := flags; switch mode { - case OpenMode.Write { + case .Write { open_flags |= OFlags.Creat | OFlags.Trunc; rights |= Rights.Write; } - case OpenMode.Append { + case .Append { open_flags |= OFlags.Creat; rights |= Rights.Write; fd_flags |= FDFlags.Append; } - case OpenMode.Read { + case .Read { rights |= Rights.Read | Rights.Seek | Rights.Tell; } } @@ -90,14 +90,14 @@ file_open :: (path: str, mode := OpenMode.Read, flags := FDFlags.Sync) -> (File, if err := wasi.path_open( DIR_FD, - LookupFlags.SymLinkFollow, + .SymLinkFollow, path, open_flags, rights, rights, fd_flags, ^file.fd); - err != Errno.Success { + err != .Success { return file, false; } @@ -108,7 +108,7 @@ file_open :: (path: str, mode := OpenMode.Read, flags := FDFlags.Sync) -> (File, } file_close :: (file: File) -> bool { - if wasi.fd_close(file.fd) != Errno.Success { + if wasi.fd_close(file.fd) != .Success { return false; } @@ -138,13 +138,13 @@ get_contents_from_file :: (file: File) -> str { wasi.fd_tell(file.fd, ^prev_loc); dummy: i64; - wasi.fd_seek(file.fd, 0, Whence.Set, ^dummy); + wasi.fd_seek(file.fd, 0, .Set, ^dummy); dummy2: u32; buf := IOVec.{ cast(u32) data, size }; wasi.fd_pread(file.fd, .{ cast(u32) ^buf, 1 }, 0, ^dummy2); - wasi.fd_seek(file.fd, prev_loc, Whence.Set, ^dummy); + wasi.fd_seek(file.fd, prev_loc, .Set, ^dummy); return data[0 .. size]; } @@ -153,7 +153,7 @@ get_contents :: proc { get_contents_from_file, (path: str) -> str { - tmp_file, success := file_open(path, OpenMode.Read); + tmp_file, success := file_open(path, .Read); if !success do return .{ null, 0 }; defer file_close(tmp_file); @@ -173,11 +173,11 @@ open :: (path: str, mode := OpenMode.Read) -> (Error, FileStream) { }; file, success := file_open(path, mode); - if !success do return Error.NotFound, fs; + if !success do return .NotFound, fs; fs.file = file; fs.vtable = ^file_stream_vtable; - return Error.None, fs; + return .None, fs; } #private @@ -186,7 +186,7 @@ file_stream_vtable := Stream_Vtable.{ // Currently, the new offset is just ignored. newoffset : wasi.Filesize; error := wasi.fd_seek(file.fd, ~~ to, ~~ whence, ^newoffset); - if error != Errno.Success do return Error.BadFile; + if error != .Success do return .BadFile; return Error.None; }, @@ -194,18 +194,18 @@ file_stream_vtable := Stream_Vtable.{ tell = (use fs: ^FileStream) -> (Error, u32) { location : wasi.Filesize; error := wasi.fd_tell(file.fd, ^location); - if error != Errno.Success do return Error.BadFile, 0; + if error != .Success do return .BadFile, 0; - return Error.None, ~~location; + return .None, ~~location; }, read = (use fs: ^FileStream, buffer: [] u8) -> (Error, u32) { bytes_read : wasi.Size; vec := IOVec.{ buf = cast(u32) buffer.data, len = buffer.count }; error := wasi.fd_read(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^bytes_read); - if error != Errno.Success do return Error.BadFile, 0; + if error != .Success do return .BadFile, 0; - return Error.None, bytes_read; + return .None, bytes_read; }, read_at = (use fs: ^FileStream, at: u32, buffer: [] u8) -> (Error, u32) { @@ -214,9 +214,9 @@ file_stream_vtable := Stream_Vtable.{ error := wasi.fd_pread(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ~~at, ^bytes_read); // FIX: Maybe report Error.OutOfBounds if the 'at' was out of bounds? - if error != Errno.Success do return Error.BadFile, 0; + if error != .Success do return .BadFile, 0; - return Error.None, bytes_read; + return .None, bytes_read; }, read_byte = (use fs: ^FileStream) -> (Error, u8) { @@ -224,22 +224,22 @@ file_stream_vtable := Stream_Vtable.{ byte : u8; vec := IOVec.{ buf = cast(u32) ^byte, len = 1}; error := wasi.fd_read(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^bytes_read); - if error != Errno.Success do return Error.BadFile, 0; + if error != .Success do return .BadFile, 0; - return Error.None, byte; + return .None, byte; }, unread_byte = (use fs: ^FileStream) -> Error { - return Error.NotImplemented; + return .NotImplemented; }, write = (use fs: ^FileStream, buffer: [] u8) -> (Error, u32) { bytes_written : wasi.Size; vec := IOVec.{ buf = cast(u32) buffer.data, len = buffer.count }; error := wasi.fd_write(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^bytes_written); - if error != Errno.Success do return Error.BadFile, 0; + if error != .Success do return .BadFile, 0; - return Error.None, bytes_written; + return .None, bytes_written; }, write_at = (use fs: ^FileStream, at: u32, buffer: [] u8) -> (Error, u32) { @@ -248,9 +248,9 @@ file_stream_vtable := Stream_Vtable.{ error := wasi.fd_pwrite(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ~~at, ^bytes_written); // FIX: Maybe report Error.OutOfBounds if the 'at' was out of bounds? - if error != Errno.Success do return Error.BadFile, 0; + if error != .Success do return .BadFile, 0; - return Error.None, bytes_written; + return .None, bytes_written; }, write_byte = (use fs: ^FileStream, byte: u8) -> Error { @@ -258,24 +258,24 @@ file_stream_vtable := Stream_Vtable.{ byte_to_write := byte; vec := IOVec.{ buf = cast(u32) ^byte_to_write, len = 1 }; error := wasi.fd_write(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^bytes_written); - if error != Errno.Success do return Error.BadFile; + if error != .Success do return .BadFile; - return Error.None; + return .None; }, close = (use fs: ^FileStream) -> Error { file_close(file); - return Error.None; + return .None; }, flush = (use fs: ^FileStream) -> Error { wasi.fd_datasync(file.fd); - return Error.None; + return .None; }, size = (use fs: ^FileStream) -> i32 { file_stat: FileStat; - if wasi.fd_filestat_get(file.fd, ^file_stat) != Errno.Success do return 0; + if wasi.fd_filestat_get(file.fd, ^file_stat) != .Success do return 0; return ~~ file_stat.size; }, @@ -288,7 +288,7 @@ file_logger_open :: (filename: str, allocator := context.allocator) -> Logger { file := new(File, allocator); success := false; - *file, success = file_open(filename, mode=OpenMode.Append); + *file, success = file_open(filename, mode=.Append); assert(success, "Unable to open file for logging."); return .{ file_logger_proc, file };