From 2eede1c47d804945ff07a57d6f5b42b2744298c2 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 19 Dec 2020 18:32:58 -0600 Subject: [PATCH] fixed arena allocator; should have tested it --- core/alloc/arena.onyx | 24 ++++++++++++------------ docs/bugs | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 docs/bugs diff --git a/core/alloc/arena.onyx b/core/alloc/arena.onyx index fba72bea..051e705c 100644 --- a/core/alloc/arena.onyx +++ b/core/alloc/arena.onyx @@ -25,8 +25,8 @@ arena_alloc_proc :: proc (data: rawptr, aa: AllocationAction, size: u32, align: retval = ss.curr_ptr; ss.curr_ptr = cast(rawptr) (cast(u32) ss.curr_ptr + size); } else { - // Not enough space for the allocation - retval = null; + // Not enough space for the allocation + retval = null; } return retval; @@ -36,20 +36,20 @@ arena_alloc_proc :: proc (data: rawptr, aa: AllocationAction, size: u32, align: } make :: proc (buffer: rawptr, length: u32) -> ArenaState { - return ArenaState.{ - base_ptr = buffer, - curr_ptr = buffer, - size = length, - }; + return ArenaState.{ + base_ptr = buffer, + curr_ptr = buffer, + size = length, + }; } make_allocator :: proc (rs: ^ArenaState) -> Allocator { - return Allocator.{ - func = ring_alloc_proc, - data = rs, - }; + return Allocator.{ + func = arena_alloc_proc, + data = rs, + }; } reset :: proc (arena: ^ArenaState) { - arena.curr_ptr = arena.base_ptr; + arena.curr_ptr = arena.base_ptr; } \ No newline at end of file diff --git a/docs/bugs b/docs/bugs new file mode 100644 index 00000000..23fd0eb4 --- /dev/null +++ b/docs/bugs @@ -0,0 +1,26 @@ +List of known bugs: + +[ ] Using an auto-cast on an argument when calling an overloaded proc leads + to an unexpected error. Take the following example: + ``` + overloaded :: proc { + proc (x: f32, y: str) ---, + proc (x: i32, y: i32) ---, + } + + foo :: proc () { + x: i32 = 1234; + overloaded(~~x, 4); + } + ``` + Compiles with the following error: + ``` + (/home/brendan/dev/c/onyx/a.onyx:8,15) unable to match overloaded function with provided argument types: (f32, unsized int) + 8 | overloaded(~~x, 4); + ``` + + This is because in trying the first overload, the auto-cast is consumed + and converted to a cast(f32). Then, when it doesn't match the first one + and it tries the second, the parameter types are f32 and unsized int, + which is doesn't match the second one, when the original parameters would + have matched correctly. \ No newline at end of file -- 2.25.1