From: Brendan Hansen Date: Tue, 5 Oct 2021 21:20:59 +0000 (-0500) Subject: better support for singular 'any' X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=0e9f19b2bcd088619e9b2c7c7daad8c33f1470f7;p=onyx.git better support for singular 'any' --- diff --git a/bin/onyx b/bin/onyx index befb0c28..19e4efc7 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/include/astnodes.h b/include/astnodes.h index 2778db73..8be59f54 100644 --- a/include/astnodes.h +++ b/include/astnodes.h @@ -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 diff --git a/modules/ui/components/radio.onyx b/modules/ui/components/radio.onyx index 502cbcb5..e2e365d0 100644 --- a/modules/ui/components/radio.onyx +++ b/modules/ui/components/radio.onyx @@ -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); } diff --git a/modules/ui/ui.onyx b/modules/ui/ui.onyx index d9153969..bf2ba311 100644 --- a/modules/ui/ui.onyx +++ b/modules/ui/ui.onyx @@ -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; } diff --git a/src/astnodes.c b/src/astnodes.c index 3ab5bac2..1563aee2 100644 --- a/src/astnodes.c +++ b/src/astnodes.c @@ -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: // diff --git a/src/utils.c b/src/utils.c index 4abd861a..459d6a25 100644 --- a/src/utils.c +++ b/src/utils.c @@ -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; } diff --git a/src/wasm.c b/src/wasm.c index a7fcfec4..3d43d6c4 100644 --- a/src/wasm.c +++ b/src/wasm.c @@ -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); } }