bugfixes; made foo(i32).{ ... } work
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 13 Nov 2021 05:19:40 +0000 (23:19 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 13 Nov 2021 05:19:40 +0000 (23:19 -0600)
core/container/bucket_array.onyx
core/container/iter.onyx
core/container/list.onyx
core/container/set.onyx
src/astnodes.c
src/checker.c
src/symres.c
src/types.c

index 852985cd421bfbcf9cb373e33ded92dabab2f36f..863cedf7d095c172f9a8ed7c643442e9fdec4f51 100644 (file)
@@ -29,7 +29,7 @@ init :: (use b: ^Bucket_Array($T), elements: i32,
     
     allocator = bucket_allocator;
     b.elements_per_bucket = elements;
-    buckets   = array.make(#type Bucket_Array.Bucket(T), allocator=array_allocator);
+    buckets   = array.make(Bucket_Array.Bucket(T), allocator=array_allocator);
 
     initial_bucket := alloc_bucket(b);
     array.push(^buckets, initial_bucket);
@@ -108,7 +108,7 @@ iterator :: (b: ^Bucket_Array($T)) -> Iterator(T) {
         elem_idx   : i32;
     }
 
-    c := new(#type Context(T));
+    c := new(Context(T));
     c.ba = b;
     c.bucket_idx = 0;
     c.elem_idx   = 0;
index 8015be0c841a061acf5bfb968ad2108e540fb89a..fc508515a76653d9c9520c785784fac386e2739b 100644 (file)
@@ -18,7 +18,7 @@ filter :: (it: Iterator($T), predicate: (T) -> bool) -> Iterator(T) {
         predicate: (T) -> bool;
     }
 
-    filter_iterator := new(#type FilterIterator(T));
+    filter_iterator := new(FilterIterator(T));
     filter_iterator.iterator = it;
     filter_iterator.predicate = predicate;
 
@@ -54,7 +54,7 @@ map :: (it: Iterator($T), transform: (T) -> $R) -> Iterator(R) {
         transform: (T) -> R;
     }
 
-    map_iterator := new(#type MapIterator(T, R));
+    map_iterator := new(MapIterator(T, R));
     map_iterator.iterator = it;
     map_iterator.transform = transform;
 
@@ -105,7 +105,7 @@ take :: (it: Iterator($T), count: u32) -> Iterator(T) {
         remaining: u32;
     }
 
-    take_iterator := new(#type TakeIterator(T));
+    take_iterator := new(TakeIterator(T));
     take_iterator.iterator = it;
     take_iterator.remaining = count;
 
@@ -134,7 +134,7 @@ take_while :: (it: Iterator($T), predicate: (T) -> bool) -> Iterator(T) {
         predicate: (T) -> bool;
     }
 
-    take_iterator := new(#type TakeIterator(T));
+    take_iterator := new(TakeIterator(T));
     take_iterator.iterator = it;
     take_iterator.predicate = predicate;
 
@@ -164,7 +164,7 @@ skip :: (it: Iterator($T), count: u32) -> Iterator(T) {
         skipped:  bool = false;
     }
 
-    skip_iterator := new(#type SkipIterator(T));
+    skip_iterator := new(SkipIterator(T));
     skip_iterator.iterator = it;
     skip_iterator.to_skip = count;
 
@@ -205,7 +205,7 @@ zip :: (left_iterator: Iterator($T), right_iterator: Iterator($R)) -> Iterator(Z
         iterator2: Iterator(R);
     }
 
-    zipped_iterator := new(#type ZippedIterator(T, R));
+    zipped_iterator := new(ZippedIterator(T, R));
     zipped_iterator.iterator1 = left_iterator;
     zipped_iterator.iterator2 = right_iterator;
 
@@ -255,7 +255,7 @@ enumerate :: (it: Iterator($T), start_index: i32 = 0) -> Iterator(Enumeration_Va
         current_index: i32;
     }
 
-    ec := make(#type Enumeration_Context(T));
+    ec := make(Enumeration_Context(T));
     ec.iterator = it;
     ec.current_index = start_index;
 
@@ -305,7 +305,7 @@ from_array :: (arr: [] $T) -> Iterator(^T) {
         current: u32;
     }
 
-    c := make(#type Context(T));
+    c := make(Context(T));
     c.data = arr.data;
     c.count = arr.count;
     c.current = 0;
index c7169efbbd3f1969675fc651255a0bd55a09a29c..a1c988247001eff1b7943673d2036fd5f60e4967 100644 (file)
@@ -109,7 +109,7 @@ get_iterator :: (list: ^List($T)) -> Iterator(T) {
         current: ^ListElem(T);
     }
 
-    list_iterator := new(#type ListIterator(T));
+    list_iterator := new(ListIterator(T));
     list_iterator.current = list.first;
 
     return .{
@@ -120,4 +120,4 @@ get_iterator :: (list: ^List($T)) -> Iterator(T) {
 }
 
 #local
-allocate_elem :: macro (list: ^List($T)) => new(#type ListElem(T), allocator=list.allocator);
+allocate_elem :: macro (list: ^List($T)) => new(ListElem(T), allocator=list.allocator);
index 89867cf3c1e3452a87358d68d61ed857b457a575..dc3c253ed0aa19807f405a3f75ad539a721e06ed 100644 (file)
@@ -107,7 +107,7 @@ iterator :: (set: ^Set($T)) -> Iterator(T) {
         position: i32;
     }
 
-    context := new(#type Context(T));
+    context := new(Context(T));
     context.entry_array = set.entries;
     context.position = 0;
 
@@ -184,4 +184,4 @@ iterator :: (set: ^Set($T)) -> Iterator(T) {
             hashes[lr.hash_index] = index;
         }
     }
-}
\ No newline at end of file
+}
index 0c7246a6f24379beea446febf96e07e67ea7024c..e91991ffa981202c0bfd83ddb6fd5a9cde06ca46 100644 (file)
@@ -714,6 +714,9 @@ Type* resolve_expression_type(AstTyped* node) {
         bh_arr_each(AstTyped *, expr, ((AstCompound *) node)->exprs) {
             resolve_expression_type(*expr);
         }
+
+        node->type = type_build_compound_type(context.ast_alloc, (AstCompound *) node);
+        return node->type;
     }
 
     if (node->kind == Ast_Kind_Argument) {
@@ -836,6 +839,8 @@ b32 cast_is_legal(Type* from_, Type* to_, char** err_msg) {
         return 0;
     }
 
+    if (from_->id == to_->id) return 1;
+
     if (from->kind == Type_Kind_Enum) from = from->Enum.backing;
     if (to->kind == Type_Kind_Enum) to = to->Enum.backing;
 
index 8b871e7a0ed41e1d851bf062b603e6a5acf440a7..79dffedf37a6d959c58b711432adfe7dad6492eb 100644 (file)
@@ -483,7 +483,25 @@ CheckStatus check_call(AstCall** pcall) {
     //      8. If callee is an intrinsic, turn call into an Intrinsic_Call node
     //      9. Check types of formal and actual params against each other, handling varargs
     AstCall* call = *pcall;
-    
+
+    {
+        AstNode* callee = strip_aliases((AstNode *) call->callee);
+        if (callee->kind == Ast_Kind_Poly_Struct_Type) {
+            // HACK HACK HACK
+            AstPolyCallType *pct = onyx_ast_node_new(context.ast_alloc, sizeof(AstPolyCallType), Ast_Kind_Poly_Call_Type);
+            pct->token = call->token;
+            pct->callee = (AstType *) callee;
+            pct->params = (AstNode **) call->args.values;
+            bh_arr_each(AstNode *, pp, pct->params) {
+                *pp = (AstNode *) (*(AstArgument **) pp)->value;
+            }
+
+            CHECK(type, (AstType *) pct);
+            *pcall = (AstCall *) pct;
+            return Check_Success;
+        }
+    }
+
     if (call->flags & Ast_Flag_Has_Been_Checked) return Check_Success;
 
     u32 current_checking_level_store = current_checking_level;
@@ -1082,11 +1100,12 @@ CheckStatus check_struct_literal(AstStructLiteral* sl) {
         // stnode is filled out.
         if (sl->stnode == NULL) return Check_Success;
 
+        CHECK(expression, &sl->stnode);
         if (!node_is_type((AstNode *) sl->stnode)) {
             ERROR(sl->token->pos, "Type used for struct literal is not a type.");
         }
 
-        fill_in_type((AstTyped *) sl);
+        sl->type = type_build_from_ast(context.ast_alloc, (AstType *) sl->stnode);
         if (sl->type == NULL)
             YIELD(sl->token->pos, "Trying to resolve type of struct literal.");
     }
@@ -1170,10 +1189,11 @@ CheckStatus check_array_literal(AstArrayLiteral* al) {
         if (al->atnode == NULL) return Check_Success;
             // YIELD(al->token->pos, "Waiting for array literal type to be known.");
 
+        CHECK(expression, &al->atnode);
         if (!node_is_type((AstNode *) al->atnode))
             ERROR(al->token->pos, "Array type is not a type.");
 
-        fill_in_type((AstTyped *) al);
+        al->type = type_build_from_ast(context.ast_alloc, (AstType *) al->atnode);
         if (al->type == NULL)
             YIELD(al->token->pos, "Trying to resolve type of array literal.");
 
index 5bbb228fb4e4ba48c07d3068a3dfe7ee6d050051..5042b48a2f0a7c082668ab529e06de8b9556b26e 100644 (file)
@@ -395,7 +395,6 @@ static SymresStatus symres_unaryop(AstUnaryOp** unaryop) {
 
 static SymresStatus symres_struct_literal(AstStructLiteral* sl) {
     if (sl->stnode != NULL) SYMRES(expression, &sl->stnode);
-    SYMRES(type, (AstType **) &sl->stnode);
 
     sl->type_node = (AstType *) sl->stnode;
     while (sl->type_node && sl->type_node->kind == Ast_Kind_Type_Alias)
@@ -408,7 +407,6 @@ static SymresStatus symres_struct_literal(AstStructLiteral* sl) {
 
 static SymresStatus symres_array_literal(AstArrayLiteral* al) {
     if (al->atnode != NULL) SYMRES(expression, &al->atnode);
-    SYMRES(type, (AstType **) &al->atnode);
 
     al->type_node = (AstType *) al->atnode;
     while (al->type_node && al->type_node->kind == Ast_Kind_Type_Alias)
index de135ae6301cad87f037ac7970fcf60f7c2f989f..77360978af0555f65996a6cf6d0bb96cd95ab965 100644 (file)
@@ -662,6 +662,11 @@ Type* type_build_compound_type(bh_allocator alloc, AstCompound* compound) {
     i64 expr_count = bh_arr_length(compound->exprs);
     fori (i, 0, expr_count) {
         if (compound->exprs[i]->type == NULL) return NULL;
+        if (compound->exprs[i]->type->kind == Type_Kind_Basic) {
+            if (compound->exprs[i]->type->Basic.kind == Basic_Kind_Int_Unsized || compound->exprs[i]->type->Basic.kind == Basic_Kind_Float_Unsized) {
+                return NULL;
+            }
+        }
     }
 
     Type* comp_type = type_create(Type_Kind_Compound, alloc, expr_count);