From a415bf8dd3d578c1068c603b2783306852b06883 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Fri, 12 Nov 2021 23:19:40 -0600 Subject: [PATCH] bugfixes; made foo(i32).{ ... } work --- core/container/bucket_array.onyx | 4 ++-- core/container/iter.onyx | 16 ++++++++-------- core/container/list.onyx | 4 ++-- core/container/set.onyx | 4 ++-- src/astnodes.c | 5 +++++ src/checker.c | 26 +++++++++++++++++++++++--- src/symres.c | 2 -- src/types.c | 5 +++++ 8 files changed, 47 insertions(+), 19 deletions(-) diff --git a/core/container/bucket_array.onyx b/core/container/bucket_array.onyx index 852985cd..863cedf7 100644 --- a/core/container/bucket_array.onyx +++ b/core/container/bucket_array.onyx @@ -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; diff --git a/core/container/iter.onyx b/core/container/iter.onyx index 8015be0c..fc508515 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -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; diff --git a/core/container/list.onyx b/core/container/list.onyx index c7169efb..a1c98824 100644 --- a/core/container/list.onyx +++ b/core/container/list.onyx @@ -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); diff --git a/core/container/set.onyx b/core/container/set.onyx index 89867cf3..dc3c253e 100644 --- a/core/container/set.onyx +++ b/core/container/set.onyx @@ -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 +} diff --git a/src/astnodes.c b/src/astnodes.c index 0c7246a6..e91991ff 100644 --- a/src/astnodes.c +++ b/src/astnodes.c @@ -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; diff --git a/src/checker.c b/src/checker.c index 8b871e7a..79dffedf 100644 --- a/src/checker.c +++ b/src/checker.c @@ -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."); diff --git a/src/symres.c b/src/symres.c index 5bbb228f..5042b48a 100644 --- a/src/symres.c +++ b/src/symres.c @@ -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) diff --git a/src/types.c b/src/types.c index de135ae6..77360978 100644 --- a/src/types.c +++ b/src/types.c @@ -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); -- 2.25.1