bugfixes with symbol resolution for polymorphic structs and add_overload
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 11 Jun 2021 14:37:15 +0000 (09:37 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 11 Jun 2021 14:37:15 +0000 (09:37 -0500)
modules/ui/components/slider.onyx
src/onyxsymres.c

index 6d077a77949e2c5d073adb4657217402fac06e1e..177891545ee526da942f2ded7d30d3c3d61046bf 100644 (file)
@@ -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);
index 8546ac7b17b66c86169e00bcf450c8678d3c584c..9dbb838ba476dcb1769362cef8601e473ca5bdb8 100644 (file)
@@ -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, &param->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);
             }