From 9907a1c4345ca41ac25cfdf9f84f448476d01d44 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Fri, 11 Jun 2021 09:37:15 -0500 Subject: [PATCH] bugfixes with symbol resolution for polymorphic structs and add_overload --- modules/ui/components/slider.onyx | 6 +++--- src/onyxsymres.c | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/modules/ui/components/slider.onyx b/modules/ui/components/slider.onyx index 6d077a77..17789154 100644 --- a/modules/ui/components/slider.onyx +++ b/modules/ui/components/slider.onyx @@ -28,7 +28,7 @@ slider :: (use r: Rectangle, value: ^$T, min_value: T, max_value: T, text: str, result = true; // Animate this? - adjust_slider_value(value, mouse_state.x - x0, width, min_value, max_value, 0); + adjust_slider_value(value, mouse_state.x - x0, width, min_value, max_value); } else { set_active_item(0); } @@ -75,7 +75,7 @@ slider :: (use r: Rectangle, value: ^$T, min_value: T, max_value: T, text: str, adjust_slider_value :: proc { @Incomplete // the step parameter is ignored. // Integers need to be - (value: ^i32, x: f32, width: f32, min_value: i32, max_value: i32, step: i32) { + (value: ^i32, x: f32, width: f32, min_value: i32, max_value: i32) { step_width := width / ~~math.abs(max_value - min_value); percent := (x + step_width / 2) / width; *value = math.lerp(percent, min_value, max_value); @@ -83,7 +83,7 @@ adjust_slider_value :: proc { }, @Incomplete // the step parameter is ignored. - (value: ^$T, x: f32, width: f32, min_value: T, max_value: T, step: T) { + (value: ^$T, x: f32, width: f32, min_value: T, max_value: T) { percent := x / width; *value = math.lerp(percent, min_value, max_value); *value = math.clamp(*value, min_value, max_value); diff --git a/src/onyxsymres.c b/src/onyxsymres.c index 8546ac7b..9dbb838b 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -107,6 +107,7 @@ static SymresStatus symres_struct_type(AstStructType* s_node) { SymresStatus ss = symres_type(&member->type_node); if (ss != Symres_Success) { s_node->flags &= ~Ast_Flag_Type_Is_Resolved; + if (s_node->scope) scope_leave(); return ss; } @@ -191,7 +192,7 @@ static SymresStatus symres_type(AstType** type) { case Ast_Kind_Poly_Struct_Type: { AstPolyStructType* pst_node = (AstPolyStructType *) *type; - pst_node->scope = scope_create(context.ast_alloc, curr_scope, pst_node->token->pos); + pst_node->scope = scope_create(context.ast_alloc, pst_node->entity->scope, pst_node->token->pos); bh_arr_each(AstPolyStructParam, param, pst_node->poly_params) { SYMRES(type, ¶m->type_node); @@ -470,15 +471,6 @@ static SymresStatus symres_return(AstReturn* ret) { } static SymresStatus symres_if(AstIfWhile* ifnode) { - if (ifnode->assignment != NULL) { - ifnode->scope = scope_create(context.ast_alloc, curr_scope, ifnode->token->pos); - scope_enter(ifnode->scope); - - SYMRES(local, &ifnode->local); - - SYMRES(statement, (AstNode **) &ifnode->assignment, NULL); - } - if (ifnode->kind == Ast_Kind_Static_If) { if ((ifnode->flags & Ast_Flag_Static_If_Resolved) == 0) { return Symres_Yield_Macro; @@ -492,6 +484,15 @@ static SymresStatus symres_if(AstIfWhile* ifnode) { } } else { + if (ifnode->assignment != NULL) { + ifnode->scope = scope_create(context.ast_alloc, curr_scope, ifnode->token->pos); + scope_enter(ifnode->scope); + + SYMRES(local, &ifnode->local); + + SYMRES(statement, (AstNode **) &ifnode->assignment, NULL); + } + SYMRES(expression, &ifnode->cond); if (ifnode->true_stmt != NULL) SYMRES(statement, (AstNode **) &ifnode->true_stmt, NULL); @@ -831,6 +832,7 @@ SymresStatus symres_function(AstFunction* func) { if (param->local->type == NULL) { // HACK HACK HACK + scope_leave(); return Symres_Yield_Macro; } } @@ -1020,6 +1022,7 @@ static SymresStatus symres_process_directive(AstNode* directive) { } else { AstOverloadedFunction* ofunc = (AstOverloadedFunction *) add_overload->overloaded_function; + SYMRES(expression, (AstTyped **) &add_overload->overload); bh_arr_push(ofunc->overloads, (AstTyped *) add_overload->overload); } -- 2.25.1