From b6abaf739ccaa226f2ddf808639994d2c0577258 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 9 Feb 2022 12:29:52 +0000 Subject: [PATCH] Add missing calls for `Object`; Add `scoped_autoreleasepool` --- core/sys/darwin/Foundation/NSAutoreleasePool.odin | 5 +++++ core/sys/darwin/Foundation/NSObject.odin | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/core/sys/darwin/Foundation/NSAutoreleasePool.odin b/core/sys/darwin/Foundation/NSAutoreleasePool.odin index 5ff2a6f1d..47cbc0e9a 100644 --- a/core/sys/darwin/Foundation/NSAutoreleasePool.odin +++ b/core/sys/darwin/Foundation/NSAutoreleasePool.odin @@ -13,3 +13,8 @@ AutoreleasePool_showPools :: proc(self: ^AutoreleasePool, obj: ^Object) { msgSend(nil, self, "showPools") } + +@(deferred_out=AutoreleasePool_drain) +scoped_autoreleasepool :: proc() -> ^AutoreleasePool { + return init(alloc(AutoreleasePool)) +} \ No newline at end of file diff --git a/core/sys/darwin/Foundation/NSObject.odin b/core/sys/darwin/Foundation/NSObject.odin index cf15dd68d..5e2f85ceb 100644 --- a/core/sys/darwin/Foundation/NSObject.odin +++ b/core/sys/darwin/Foundation/NSObject.odin @@ -33,14 +33,19 @@ retain :: proc(self: ^$T) -> ^T where intrinsics.type_is_subtype_of(T, Object) { release :: proc(self: ^$T) where intrinsics.type_is_subtype_of(T, Object) { msgSend(nil, self, "release") } +autorelease :: proc(self: ^$T) where intrinsics.type_is_subtype_of(T, Object) { + msgSend(nil, self, "autorelease") +} retainCount :: proc(self: ^$T) -> UInteger where intrinsics.type_is_subtype_of(T, Object) { return msgSend(UInteger, self, "retainCount") } + copy :: proc(self: ^Copying($T)) -> ^T where intrinsics.type_is_subtype_of(T, Object) { return msgSend(^T, self, "copy") } + hash :: proc(self: ^Object) -> UInteger { return msgSend(UInteger, self, "hash") } @@ -60,6 +65,10 @@ debugDescription :: proc(self: ^Object) -> ^String { return nil } +bridgingCast :: proc($T: typeid, obj: ^Object) where intrinsics.type_is_pointer(T), intrinsics.type_is_subtype_of(T, ^Object) { + return (T)(obj) +} + @(objc_class="NSCoder") Coder :: struct {using _: Object}