Implementes the block ABI.2010.3.16 natively via the objc_block intrinsic and the Objc_Block builtin type.

See: https://clang.llvm.org/docs/Block-ABI-Apple.html
This commit is contained in:
Harold Brenes
2025-08-06 20:27:31 -04:00
parent 09a1e170bc
commit 9d8e15b3af
9 changed files with 644 additions and 2 deletions
+5
View File
@@ -5,6 +5,11 @@ import "base:intrinsics"
@builtin
Maybe :: union($T: typeid) {T}
/*
Represents an Objective-C block with a given procedure signature T
*/
@builtin
Objc_Block :: struct($T: typeid) where intrinsics.type_is_proc(T) { using _: intrinsics.objc_object }
/*
Recovers the containing/parent struct from a pointer to one of its fields.
+11 -1
View File
@@ -1,9 +1,12 @@
#+private
package runtime
@(priority_index=-1e6)
@(priority_index=-1e5)
foreign import ObjC "system:objc"
@(priority_index=-1e6)
foreign import libSystem "system:System"
import "base:intrinsics"
objc_id :: ^intrinsics.objc_object
@@ -34,3 +37,10 @@ foreign ObjC {
object_getClass :: proc "c" (obj: objc_id) -> objc_Class ---
}
foreign libSystem {
_NSConcreteGlobalBlock: intrinsics.objc_class
_NSConcreteStackBlock: intrinsics.objc_class
_Block_object_assign :: proc "c" (rawptr, rawptr, i32) ---
_Block_object_dispose :: proc "c" (rawptr, i32) ---
}