better error message; using auto polymorphic
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 5 Jan 2022 03:53:47 +0000 (21:53 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 5 Jan 2022 03:53:47 +0000 (21:53 -0600)
core/container/heap.onyx
core/container/set.onyx
src/checker.c

index 61516f35d5307d4b7bd28e35f37dcf27fbaab2c1..ae8c388ddbcd06e58a096b39fd2ada482b88e8d5 100644 (file)
@@ -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;
index d2c7f3bd0b01ad85a63b03d7dbc332844e2aa133..dbc5ad6e578311bb41799c2812722e777b90e62a 100644 (file)
@@ -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);
index 150d46094594e9e72c1e885c75c1659bd618f668..fa05dac1e0637dcef7c69c63519d1adc7a2d9106 100644 (file)
     } \
     } 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;