From: Brendan Hansen Date: Wed, 18 Aug 2021 12:36:43 +0000 (-0500) Subject: cleanup and random additions X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=b83d7148614dde0c43db23f203e9e9b954fd53e4;p=onyx.git cleanup and random additions --- diff --git a/bin/onyx b/bin/onyx index 755a2379..828be457 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/container/set.onyx b/core/container/set.onyx index ceb87d65..9f5b163b 100644 --- a/core/container/set.onyx +++ b/core/container/set.onyx @@ -50,6 +50,8 @@ insert :: (use set: ^Set($T), value: T) { hashes[lr.hash_index] = entries.count - 1; } +#operator << macro (set: Set($T), value: T) do (package core.set).insert(^set, value); + has :: (use set: ^Set($T), value: T) -> bool { lr := lookup(set, value); return lr.entry_index >= 0; diff --git a/core/io/file.onyx b/core/io/file.onyx index c13f99a5..5d250d81 100644 --- a/core/io/file.onyx +++ b/core/io/file.onyx @@ -72,12 +72,12 @@ file_open :: (path: str, mode := OpenMode.Read, flags := FDFlags.Sync) -> (File, switch mode { case .Write { open_flags |= OFlags.Creat | OFlags.Trunc; - rights |= Rights.Write; + rights |= Rights.Write | Rights.Seek | Rights.Tell; } case .Append { open_flags |= OFlags.Creat; - rights |= Rights.Write; + rights |= Rights.Write | Rights.Seek | Rights.Tell; fd_flags |= FDFlags.Append; } diff --git a/core/memory.onyx b/core/memory.onyx index 2f0ae4ad..17a99ea9 100644 --- a/core/memory.onyx +++ b/core/memory.onyx @@ -38,7 +38,7 @@ alloc_slice :: (sl: ^[] $T, count: i32, allocator := context.allocator) { } make_slice :: ($T: type_expr, count: i32, allocator := context.allocator) -> [] T { - return <[] T>.{ + return .{ data = raw_alloc(allocator, sizeof T * count), count = count }; @@ -52,6 +52,13 @@ free_slice :: (sl: ^[] $T, allocator := context.allocator) { sl.count = 0; } +copy_slice :: (sl: [] $T, allocator := context.allocator) -> [] T { + data := raw_alloc(allocator, sl.count * sizeof T); + copy(data, sl.data, sl.count * sizeof T); + + return .{ data = data, count = sl.count }; +} + align :: #match { (size: ^u64, align: u64) { if *size % align != 0 { diff --git a/core/string.onyx b/core/string.onyx index 66266453..4cafb683 100644 --- a/core/string.onyx +++ b/core/string.onyx @@ -169,7 +169,6 @@ ends_with :: (s: str, suffix: str) -> bool { return true; } - strip_leading_whitespace :: #match { (s: ^str) { while true do switch s.data[0] { diff --git a/modules/ui/components/scrollable_region.onyx b/modules/ui/components/scrollable_region.onyx index 1f30bab3..5b9d188d 100644 --- a/modules/ui/components/scrollable_region.onyx +++ b/modules/ui/components/scrollable_region.onyx @@ -12,7 +12,15 @@ Scrollable_Region_State :: struct { #private scrollable_region_states : map.Map(UI_Id, Scrollable_Region_State); -scrollable_region_start :: (use r: Rectangle, minimum_y := 0.0f, maximum_y := 10000.0f, site := #callsite, state: ^Scrollable_Region_State = null) { +Scrollable_Region_Controls :: struct { + minimum_y := 0.0f; + maximum_y := 10000.0f; // Senseless default + minimum_x := 0.0f; + maximum_x := 10000.0f; // Senseless default +} + +scrollable_region_start :: (use r: Rectangle, use src: Scrollable_Region_Controls = .{}, + site := #callsite, state: ^Scrollable_Region_State = null) { hash := get_site_hash(site, 0); x, y := Rectangle.top_left(r); width, height := Rectangle.dimensions(r); @@ -36,11 +44,14 @@ scrollable_region_start :: (use r: Rectangle, minimum_y := 0.0f, maximum_y := 10 if is_key_down(38) do state.transform.translation.y += speed; if is_key_down(40) do state.transform.translation.y -= speed; + if is_key_down(37) do state.transform.translation.x -= speed; + if is_key_down(39) do state.transform.translation.x += speed; if mouse_state.dwheel > 0 do state.transform.translation.y += speed; if mouse_state.dwheel < 0 do state.transform.translation.y -= speed; state.transform.translation.y = math.clamp(state.transform.translation.y, -maximum_y, minimum_y); + state.transform.translation.x = math.clamp(state.transform.translation.x, -maximum_x, minimum_x); } gfx.push_scissor(x, y, width, height); diff --git a/src/onyxastnodes.c b/src/onyxastnodes.c index 45f4f04c..86c30aa8 100644 --- a/src/onyxastnodes.c +++ b/src/onyxastnodes.c @@ -715,6 +715,15 @@ b32 cast_is_legal(Type* from_, Type* to_, char** err_msg) { Type* from = from_; Type* to = to_; + if (from == NULL) { + if (err_msg) *err_msg = "'from' is null. (Compiler Error)"; + return 0; + } + if (to == NULL) { + if (err_msg) *err_msg = "'to' is null. (Compiler Error)"; + return 0; + } + if (from->kind == Type_Kind_Enum) from = from->Enum.backing; if (to->kind == Type_Kind_Enum) to = to->Enum.backing; diff --git a/src/onyxclone.c b/src/onyxclone.c index 3c0b5f2c..8b5e8531 100644 --- a/src/onyxclone.c +++ b/src/onyxclone.c @@ -17,6 +17,7 @@ static inline b32 should_clone(AstNode* node) { case Ast_Kind_Polymorphic_Proc: case Ast_Kind_Alias: case Ast_Kind_Code_Block: + case Ast_Kind_Macro: return 0; default: return 1;