From 22e2a1d5a2c95d02330e810b3fcc942411c09627 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 4 Jan 2022 21:53:47 -0600 Subject: [PATCH] better error message; using auto polymorphic --- core/container/heap.onyx | 6 +++--- core/container/set.onyx | 12 ++++++------ src/checker.c | 11 ++++++++++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/core/container/heap.onyx b/core/container/heap.onyx index 61516f35..ae8c388d 100644 --- a/core/container/heap.onyx +++ b/core/container/heap.onyx @@ -27,7 +27,7 @@ insert :: (use heap: ^Heap($T), v: T) { #operator << macro (heap: Heap($T), v: T) do (package core.heap).insert(^heap, v); -remove_top :: (use heap: ^Heap($T)) -> T { +remove_top :: (use heap: ^Heap) -> heap.T { x := data[0]; array.fast_delete(^data, 0); shift_down(heap, 0); @@ -39,7 +39,7 @@ remove_top :: (use heap: ^Heap($T)) -> T { heap_lchild :: macro (index) => (index * 2) + 1 heap_rchild :: macro (index) => (index * 2) + 2 - shift_down :: (use heap: ^Heap($T), idx: i32) { + shift_down :: (use heap: ^Heap, idx: i32) { while true { min_index := idx; @@ -67,7 +67,7 @@ remove_top :: (use heap: ^Heap($T)) -> T { } } - shift_up :: (use heap: ^Heap($T), idx: i32) { + shift_up :: (use heap: ^Heap, idx: i32) { while idx > 0 { parent := heap_parent(idx); if compare(data[parent], data[idx]) <= 0 do break; diff --git a/core/container/set.onyx b/core/container/set.onyx index d2c7f3bd..dbc5ad6e 100644 --- a/core/container/set.onyx +++ b/core/container/set.onyx @@ -51,7 +51,7 @@ init :: (use set: ^Set($T), default := __zero_value(T)) { array.init(^entries, 4, allocator=allocator); } -free :: (use set: ^Set($T)) { +free :: (use set: ^Set) { memory.free_slice(^hashes, allocator=allocator); array.free(^entries); } @@ -98,12 +98,12 @@ remove :: (use set: ^Set($T), value: T) { else do hashes[last.hash_index] = lr.entry_index; } -clear :: (use set: ^Set($T)) { +clear :: (use set: ^Set) { array.fill(hashes, -1); array.clear(^entries); } -empty :: (use set: ^Set($T)) -> bool { +empty :: (use set: ^Set) -> bool { return entries.count == 0; } @@ -168,14 +168,14 @@ iterator :: (set: ^Set($T)) -> Iterator(T) { return lr; } - full :: (use set: ^Set($T)) => entries.count >= ~~(0.75f * ~~hashes.count); + full :: (use set: ^Set) => entries.count >= ~~(0.75f * ~~hashes.count); - grow :: (use set: ^Set($T)) { + grow :: (use set: ^Set) { new_size := math.max(hashes.count << 1, 8); rehash(set, new_size); } - rehash :: (use set: ^Set($T), new_size: i32) { + rehash :: (use set: ^Set, new_size: i32) { memory.free_slice(^hashes, allocator); memory.alloc_slice(^hashes, new_size, allocator); memory.fill_slice(hashes, -1); diff --git a/src/checker.c b/src/checker.c index 150d4609..fa05dac1 100644 --- a/src/checker.c +++ b/src/checker.c @@ -29,6 +29,15 @@ } \ } while (0) +#define YIELD_ERROR(loc, msg) do { \ + if (context.cycle_detected) { \ + onyx_report_error(loc, Error_Critical, msg); \ + return Check_Error; \ + } else { \ + return Check_Yield_Macro; \ + } \ + } while (0) + #define ERROR(loc, msg) do { \ onyx_report_error(loc, Error_Critical, msg); \ return Check_Error; \ @@ -125,7 +134,7 @@ CheckStatus check_return(AstReturn* retnode) { if (*expected_return_type == &type_auto_return) { resolve_expression_type(retnode->expr); if (retnode->expr->type == NULL) - YIELD(retnode->token->pos, "Trying to determine automatic return type."); + YIELD_ERROR(retnode->token->pos, "Unable to determine the automatic return type here."); *expected_return_type = retnode->expr->type; return Check_Success; -- 2.25.1