From 5af13f5d53b4e5f5d472cd8a8bc4444f05ea36d6 Mon Sep 17 00:00:00 2001 From: Harold Brenes Date: Tue, 16 Sep 2025 00:49:31 -0400 Subject: Automatically emit objc_msgSend calls when calling imported or implemented Objective-C methods - Add intrinsics.objc_super() - Emit objc_msgSendSuper2 calls when an objc method call is combined with objc_super(self) - Fix objc_block return value ABI for large struct returns - Fix objc_implement method wrappers bad ABI for large struct returns and indirect args - Simplify parameter forwarding for objc_imlpement methods - Add intrinsics.objc_instancetype to mimi Objective-C instancetype* returns This facilitates returning the correct type on subclasses when calling mehtods such as `alloc`, `init`, `retain`, etc. - Refactor Objective-C class implementations generation so that hierarchies are properly initialized - Better codegen for context passing with ivar-based autocontext - Allow @superclass on imported objc-c objects - Better codegen for block forwarding invoker, arguments are forwarded directly --- src/types.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/types.cpp') diff --git a/src/types.cpp b/src/types.cpp index effa8ef64..372c2e991 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -752,11 +752,14 @@ gb_global Type *t_objc_object = nullptr; gb_global Type *t_objc_selector = nullptr; gb_global Type *t_objc_class = nullptr; gb_global Type *t_objc_ivar = nullptr; +gb_global Type *t_objc_super = nullptr; // Struct used in lieu of the 'self' instance when calling objc_msgSendSuper. +gb_global Type *t_objc_super_ptr = nullptr; gb_global Type *t_objc_id = nullptr; gb_global Type *t_objc_SEL = nullptr; gb_global Type *t_objc_Class = nullptr; gb_global Type *t_objc_Ivar = nullptr; +gb_global Type *t_objc_instancetype = nullptr; // Special distinct variant of t_objc_id used mimic auto-typing of instancetype* in Objective-C enum OdinAtomicMemoryOrder : i32 { OdinAtomicMemoryOrder_relaxed = 0, // unordered @@ -4735,6 +4738,14 @@ gb_internal bool is_type_objc_object(Type *t) { return internal_check_is_assignable_to(t, t_objc_object); } +gb_internal bool is_type_objc_ptr_to_object(Type *t) { + // NOTE (harold): is_type_objc_object() returns true if it's a pointer to an object or the object itself. + // This returns true ONLY if Type is a shallow pointer to an Objective-C object. + + Type *elem = type_deref(t); + return elem != t && elem->kind == Type_Named && is_type_objc_object(elem); +} + gb_internal Type *get_struct_field_type(Type *t, isize index) { t = base_type(type_deref(t)); GB_ASSERT(t->kind == Type_Struct); -- cgit v1.2.3 From b3dfd34f2d3ca1431e3e5d8f8157b545afa45b3e Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Sat, 11 Oct 2025 14:57:45 +0200 Subject: #5788 --- src/types.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/types.cpp') diff --git a/src/types.cpp b/src/types.cpp index 372c2e991..b4cc67d83 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -1725,7 +1725,7 @@ gb_internal bool is_type_u8_ptr(Type *t) { t = base_type(t); if (t == nullptr) { return false; } if (t->kind == Type_Pointer) { - return is_type_u8(t->Slice.elem); + return is_type_u8(t->Pointer.elem); } return false; } @@ -1766,7 +1766,7 @@ gb_internal bool is_type_u16_ptr(Type *t) { t = base_type(t); if (t == nullptr) { return false; } if (t->kind == Type_Pointer) { - return is_type_u16(t->Slice.elem); + return is_type_u16(t->Pointer.elem); } return false; } -- cgit v1.2.3 From e6754547aba1df61af2fc302a100762c09fe215f Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Sat, 11 Oct 2025 15:17:23 +0200 Subject: Fix #5786 --- src/types.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/types.cpp') diff --git a/src/types.cpp b/src/types.cpp index b4cc67d83..66c87a25d 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -410,7 +410,7 @@ gb_internal u32 type_info_flags_of_type(Type *type) { flags |= TypeInfoFlag_Comparable; } if (is_type_simple_compare(type)) { - flags |= TypeInfoFlag_Comparable; + flags |= TypeInfoFlag_Simple_Compare; } return flags; } -- cgit v1.2.3 From 5dbade87e9cc806d581a563b9b587eaf7314fafd Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Sat, 11 Oct 2025 15:43:30 +0200 Subject: Simple compare is also comparable --- src/types.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/types.cpp') diff --git a/src/types.cpp b/src/types.cpp index 66c87a25d..cb830d08d 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -410,7 +410,7 @@ gb_internal u32 type_info_flags_of_type(Type *type) { flags |= TypeInfoFlag_Comparable; } if (is_type_simple_compare(type)) { - flags |= TypeInfoFlag_Simple_Compare; + flags |= TypeInfoFlag_Comparable|TypeInfoFlag_Simple_Compare; } return flags; } -- cgit v1.2.3