aboutsummaryrefslogtreecommitdiff
path: root/core/sys/darwin/Foundation/objc.odin
blob: 673996cbe6e87854d6c3798810a101bed6a101ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package objc_Foundation

foreign import "system:Foundation.framework"
// NOTE: Most of our bindings are reliant on Cocoa (everything under appkit) so just unconditionally import it
@(require) foreign import "system:Cocoa.framework"

import "base:intrinsics"
import "core:c"

IMP :: proc "c" (object: id, sel: SEL, #c_vararg args: ..any) -> id

foreign Foundation {
	objc_lookUpClass       :: proc "c" (name: cstring) -> Class ---
	sel_registerName       :: proc "c" (name: cstring) -> SEL ---
	objc_allocateClassPair :: proc "c" (superclass : Class, name : cstring, extraBytes : c.size_t) -> Class ---
	objc_registerClassPair :: proc "c" (cls : Class) ---

	class_addMethod         :: proc "c" (cls: Class, name: SEL, imp: IMP, types: cstring) -> BOOL ---
	class_getInstanceMethod :: proc "c" (cls: Class, name: SEL) -> Method ---
	class_createInstance    :: proc "c" (cls: Class, extraBytes: c.size_t) -> id ---

	method_setImplementation :: proc "c" (method: Method, imp: IMP) ---
	object_getIndexedIvars   :: proc(obj: id) -> rawptr ---
}


@(objc_class="NSZone")
Zone :: struct {using _: Object}

@(link_prefix="NS")
foreign Foundation {
	AllocateObject   :: proc "c" (aClass: Class, extraBytes: UInteger, zone: ^Zone) -> id ---
	DeallocateObject :: proc "c" (object: id) ---
}

Method :: ^objc_method
objc_method :: struct {
	method_name:  SEL,
	method_types: cstring,
	method_imp:   IMP,
}
objc_method_list :: struct {}

objc_ivar :: struct {}
objc_ivar_list :: struct {}

objc_cache :: struct {
	mask:     u32,
	occupied: u32,
	buckets:  [1]Method,
}

objc_protocol_list :: struct {
	next:  ^objc_protocol_list,
	count: c.int,
	list:  [1]^Protocol,
}

@(objc_class="Protocol")
Protocol :: struct{using _: intrinsics.objc_object}

objc_object_internals :: struct {
	isa: ^objc_class_internals,
}


objc_class_internals :: struct {
	isa:           Class,
	super_class:   Class,
	name:          cstring,
	version:       c.long,
	info:          c.long,
	instance_size: c.long,
	ivars:         ^objc_ivar_list,
	
	methodLists:   ^^objc_method_list,

	cache:         rawptr,
	protocols:     rawptr,

}