added logging allocator; `proc` is even more optional
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 21 Jan 2021 14:17:06 +0000 (08:17 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 21 Jan 2021 14:17:06 +0000 (08:17 -0600)
bin/onyx
core/alloc.onyx
core/alloc/logging.onyx [new file with mode: 0644]
onyx.exe
src/onyxparser.c

index 273da230c2535210567e80f0cc4f32db2135427d..ddc44fd8d5c55fcc87e23c84ddb3168cccd57be6 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 9950f9a4c91d5176e78108036a8a996baf056fd4..9d7d25b46beb287ecad5ff2e05f9165f2246aa38 100644 (file)
@@ -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 (file)
index 0000000..6b49c20
--- /dev/null
@@ -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
index 9c28c097f0b3fc68d380018add75cd4cd31b88e0..381c62a0cef6cc1147b387a585d5b282f8805003 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
index 9273549ef3dc8b2f392263a7c29b680b57be6eca..1b5054f6fb8987662a5c5cd853f052ae2024120a 100644 (file)
@@ -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);