better support for singular 'any'
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 5 Oct 2021 21:20:59 +0000 (16:20 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 5 Oct 2021 21:20:59 +0000 (16:20 -0500)
bin/onyx
include/astnodes.h
modules/ui/components/radio.onyx
modules/ui/ui.onyx
src/astnodes.c
src/utils.c
src/wasm.c

index befb0c2879efd09b865456bfd0f68cb9a852c151..19e4efc76bfeb14c46b4f953507dad8a6659f44a 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 2778db73b1525ce1647eacb1c29ee3bd8e52a788..8be59f5480788d2b54178e6557aa166fd7a89b27 100644 (file)
@@ -547,11 +547,19 @@ struct AstUnaryOp       { AstTyped_base; UnaryOp operation; AstTyped *expr; };
 struct AstNumLit        { AstTyped_base; union { i32 i; i64 l; f32 f; f64 d; } value; };
 struct AstStrLit        { AstTyped_base; u64 addr; u64 length; };
 struct AstLocal         { AstTyped_base; };
-struct AstArgument      { AstTyped_base; AstTyped *value; VarArgKind va_kind; b32 is_baked : 1; };
 struct AstAddressOf     { AstTyped_base; AstTyped *expr; };
 struct AstDereference   { AstTyped_base; AstTyped *expr; };
 struct AstSizeOf        { AstTyped_base; AstType *so_ast_type; Type *so_type; u64 size; };
 struct AstAlignOf       { AstTyped_base; AstType *ao_ast_type; Type *ao_type; u64 alignment; };
+struct AstArgument      {
+    AstTyped_base;
+
+    AstTyped *value;
+
+    VarArgKind va_kind;
+    b32 is_baked : 1;
+    b32 pass_as_any : 1;
+};
 struct AstSubscript   {
     AstTyped_base;
     BinaryOp __unused_operation; // This will be set to Binary_Op_Subscript
index 502cbcb566833fead8816a7ddcee16d48be0648e..e2e365d0674aa9137b7f313aab97f844341e5a04 100644 (file)
@@ -50,6 +50,10 @@ radio :: (use r: Rectangle, selected: ^$T, value: T, text: str, theme := ^defaul
 
     if is_hot_item(hash) {
         move_towards(^animation_state.hover_time, 1.0f, theme.hover_speed);
+
+        #if #defined(set_cursor) {
+            set_cursor(Cursors.Pointer);
+        }
     } else {
         move_towards(^animation_state.hover_time, 0.0f, theme.hover_speed);
     }
index d9153969444d33048898b580da345371f2c58a44..bf2ba31161176388aef18bf2661f96b62388f42c 100644 (file)
@@ -209,7 +209,6 @@ get_animation :: (id: UI_Id) -> ^Animation_State {
         retval = map.get_ptr(^animation_states, id);
     }
 
-    // printf("{*}\n", retval);
     retval.accessed_this_frame = true;
     return retval;
 }
index 3ab5bac2ee7713f7496c3007c51eac51719c80f8..1563aee262c316bd34dbac7f7b614ad422b012e7 100644 (file)
@@ -582,6 +582,9 @@ b32 unify_node_and_type_(AstTyped** pnode, Type* type, b32 permanent) {
     Type* node_type = get_expression_type(node);
     if (types_are_compatible(node_type, type)) return 1;
 
+    i64 any_id = type_build_from_ast(context.ast_alloc, builtin_any_type)->id;
+    if (node_type && node_type->id != any_id && type->id == any_id) return 1;
+
     // Here are some of the ways you can unify a node with a type if the type of the
     // node does not match the given type:
     // 
index 4abd861a05b310ffa0b3837d3cef8d4040f54275..459d6a252b9c8f409aea748560e71950b1c8cbe3 100644 (file)
@@ -837,6 +837,11 @@ b32 check_arguments_against_type(Arguments* args, TypeFunction* func_type, VarAr
                     return 0;
                 }
 
+                if (arg_arr[arg_pos]->value->type && arg_arr[arg_pos]->value->type->id != any_type_id && formal_params[arg_pos]->id == any_type_id) {
+                    resolve_expression_type(arg_arr[arg_pos]->value);
+                    arg_arr[arg_pos]->pass_as_any = 1;
+                }
+
                 arg_arr[arg_pos]->va_kind = VA_Kind_Not_VA;
                 break;
             }
index a7fcfec4a17c0366f93aafb0fa2b68afc902046f..3d43d6c40c6b8deee48f7c4c4894fcef7d3a00a7 100644 (file)
@@ -1439,6 +1439,10 @@ EMIT_FUNC(call, AstCall* call) {
             vararg_count += 1;
         }
 
+        if (arg->pass_as_any) {
+            place_on_stack = 1;
+        }
+
         if (place_on_stack) WIL(WI_LOCAL_GET, stack_top_store_local);
 
         emit_expression(mod, &code, arg->value);
@@ -1458,6 +1462,10 @@ EMIT_FUNC(call, AstCall* call) {
                 vararg_any_types[vararg_count - 1] = arg->value->type->id;
             }
 
+            if (arg->pass_as_any) {
+                WIL(WI_I32_CONST, arg->value->type->id);
+            }
+
             reserve_size += type_size_of(arg->value->type);
         }
     }