From: Brendan Hansen Date: Thu, 21 Jan 2021 14:17:06 +0000 (-0600) Subject: added logging allocator; `proc` is even more optional X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=28428646690c759dd3a2df6a525551335ffe9e50;p=onyx.git added logging allocator; `proc` is even more optional --- diff --git a/bin/onyx b/bin/onyx index 273da230..ddc44fd8 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/alloc.onyx b/core/alloc.onyx index 9950f9a4..9d7d25b4 100644 --- a/core/alloc.onyx +++ b/core/alloc.onyx @@ -5,6 +5,7 @@ package core.alloc #load "core/alloc/heap" #load "core/alloc/ring" #load "core/alloc/pool" +#load "core/alloc/logging" TEMPORARY_ALLOCATOR_SIZE :: 1 << 12; // 4Kb diff --git a/core/alloc/logging.onyx b/core/alloc/logging.onyx new file mode 100644 index 00000000..6b49c201 --- /dev/null +++ b/core/alloc/logging.onyx @@ -0,0 +1,26 @@ +package core.alloc.log + +Allocation_Action_Strings := str.[ + " alloc", + "resize", + " free", +]; + +#private_file +logging_allocator_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: u32, oldptr: rawptr) -> rawptr { + allocator := cast(^Allocator) data; + res := allocator.func(allocator.data, aa, size, align, oldptr); + + use package core { printf } + printf("%s with size %i, align %i, oldptr %p returns %p\n", + Allocation_Action_Strings[cast(u32) aa], size, align, oldptr, res); + + return res; +} + +logging_allocator :: (alloc: ^Allocator) -> Allocator { + return Allocator.{ + func = logging_allocator_proc, + data = alloc, + }; +} \ No newline at end of file diff --git a/onyx.exe b/onyx.exe index 9c28c097..381c62a0 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyxparser.c b/src/onyxparser.c index 9273549e..1b5054f6 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -2113,18 +2113,15 @@ static b32 parse_possible_function_definition(OnyxParser* parser, AstTyped** ret && token_after_paren->type != Token_Type_Empty_Block) return 0; - b32 hit_colon = 0; + b32 is_params = (parser->curr + 1) == matching_paren; OnyxToken* tmp_token = parser->curr; - while (tmp_token < matching_paren) { - if (tmp_token->type == ':') { - hit_colon = 1; - break; - } + while (!is_params && tmp_token < matching_paren) { + if (tmp_token->type == ':') is_params = 1; tmp_token++; } - if (!hit_colon) return 0; + if (!is_params) return 0; OnyxToken* proc_token = parser->curr; AstFunction* func_node = parse_function_definition(parser, proc_token);