comparison dwt/internal/objc/runtime.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents 642f460a0908
children cfa563df4fdd
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
7 */ 7 */
8 module dwt.internal.objc.runtime; 8 module dwt.internal.objc.runtime;
9 9
10 import tango.stdc.stringz; 10 import tango.stdc.stringz;
11 11
12 import dwt.dwthelper.utils : String; 12 import derelict.sdl.macinit.runtime;
13 import dwt.dwthelper.utils;
13 import dwt.internal.cocoa.NSPoint; 14 import dwt.internal.cocoa.NSPoint;
14 import dwt.internal.cocoa.NSRange; 15 import dwt.internal.cocoa.NSRange;
15 import dwt.internal.cocoa.NSSize; 16 import dwt.internal.cocoa.NSSize;
16 import dwt.internal.cocoa.NSRect; 17 import dwt.internal.cocoa.NSRect;
17 static import dwt.internal.objc.bindings; 18 static import dwt.internal.objc.bindings;
18 19
19
20 extern (C)
21 {
22 alias objc_ivar* Ivar; 20 alias objc_ivar* Ivar;
23 alias objc_method* Method; 21 alias objc_method* Method;
24 alias objc_object Protocol; 22 alias objc_object Protocol;
25 23
26 alias char* SEL; 24 alias char* SEL;
28 alias objc_object* id; 26 alias objc_object* id;
29 27
30 alias extern (C) id function(id, SEL, ...) IMP; 28 alias extern (C) id function(id, SEL, ...) IMP;
31 29
32 struct objc_object 30 struct objc_object
33 { 31 {
34 Class isa; 32 Class isa;
35 } 33 }
36 34
37 struct objc_super 35 struct objc_super
38 { 36 {
39 id receiver; 37 id receiver;
40 Class clazz; 38 Class clazz;
41 39
42 // for dwt compatibility 40 // for dwt compatibility
43 alias clazz cls; 41 alias clazz cls;
44 } 42 }
45 43
46 struct objc_class 44 struct objc_class
47 { 45 {
48 Class isa; 46 Class isa;
49 Class super_class; 47 Class super_class;
50 const char* name; 48 const char* name;
51 int versionn; 49 int versionn;
52 int info; 50 int info;
53 int instance_size; 51 int instance_size;
54 objc_ivar_list* ivars; 52 objc_ivar_list* ivars;
55 objc_method_list** methodLists; 53 objc_method_list** methodLists;
56 objc_cache* cache; 54 objc_cache* cache;
57 objc_protocol_list* protocols; 55 objc_protocol_list* protocols;
58 } 56 }
59 57
60 struct objc_ivar 58 struct objc_ivar
61 { 59 {
62 char* ivar_name; 60 char* ivar_name;
63 char* ivar_type; 61 char* ivar_type;
64 int ivar_offset; 62 int ivar_offset;
65 63
66 version (X86_64) 64 version (X86_64)
67 int space; 65 int space;
68 } 66 }
69 67
70 struct objc_ivar_list 68 struct objc_ivar_list
71 { 69 {
72 int ivar_count; 70 int ivar_count;
73 71
74 version (X86_64) 72 version (X86_64)
75 int space; 73 int space;
76 74
77 /* variable length structure */ 75 /* variable length structure */
78 objc_ivar ivar_list[1]; 76 objc_ivar ivar_list[1];
79 } 77 }
80 78
81 struct objc_method 79 struct objc_method
82 { 80 {
83 SEL method_name; 81 SEL method_name;
84 char* method_types; 82 char* method_types;
85 IMP method_imp; 83 IMP method_imp;
86 } 84 }
87 85
88 struct objc_method_list 86 struct objc_method_list
89 { 87 {
90 objc_method_list* obsolete; 88 objc_method_list* obsolete;
91 89
92 int method_count; 90 int method_count;
93 91
94 version (X86_64) 92 version (X86_64)
95 int space; 93 int space;
96 94
97 /* variable length structure */ 95 /* variable length structure */
98 objc_method method_list[1]; 96 objc_method method_list[1];
99 } 97 }
100 98
101 struct objc_cache 99 struct objc_cache
102 { 100 {
103 uint mask /* total = mask + 1 */; 101 uint mask /* total = mask + 1 */;
104 uint occupied; 102 uint occupied;
105 Method buckets[1]; 103 Method buckets[1];
106 } 104 }
107 105
108 struct objc_protocol_list 106 struct objc_protocol_list
109 { 107 {
110 objc_protocol_list* next; 108 objc_protocol_list* next;
111 long count; 109 long count;
112 Protocol* list[1]; 110 Protocol* list[1];
111 }
112
113
114
115 alias dwt.internal.objc.bindings.objc_registerClassPair objc_registerClassPair;
116 alias dwt.internal.objc.bindings.class_addProtocol class_addProtocol;
117 alias dwt.internal.objc.bindings.instrumentObjcMessageSends instrumentObjcMessageSends;
118 alias dwt.internal.objc.bindings.object_getClass object_getClass;
119 alias dwt.internal.objc.bindings.object_setClass object_setClass;
120
121
122 bool class_addIvar (Class cls, String name, size_t size, byte alignment, String types)
123 {
124 return dwt.internal.objc.bindings.class_addIvar(cls, name.ptr, size, alignment, types.ptr);
125 }
126
127 bool class_addMethod (Class cls, SEL name, IMP imp, String types)
128 {
129 return dwt.internal.objc.bindings.class_addMethod(cls, name, imp, types.ptr);
130 }
131
132 IMP class_getMethodImplementation (Class cls, SEL name)
133 {
134 return dwt.internal.objc.bindings.class_getMethodImplementation(cls, name);
135 }
136
137 String class_getName (Class cls)
138 {
139 return fromStringz(dwt.internal.objc.bindings.class_getName(cls));
140 }
141
142 Class objc_allocateClassPair (Class superclass, String name, size_t extraBytes)
143 {
144 return dwt.internal.objc.bindings.objc_allocateClassPair(superclass, name.ptr, extraBytes);
145 }
146
147 id objc_getClass (String name)
148 {
149 return dwt.internal.objc.bindings.objc_getClass(name.ptr);
150 }
151
152 Protocol* objc_getProtocol (String name)
153 {
154 return dwt.internal.objc.bindings.objc_getProtocol(name.ptr);
155 }
156
157 id objc_lookUpClass (String name)
158 {
159 return dwt.internal.objc.bindings.objc_lookUpClass(name.ptr);
160 }
161
162 SEL object_getClassName (id obj)
163 {
164 return dwt.internal.objc.bindings.object_getClassName(obj);
165 }
166
167 Ivar object_getInstanceVariable (id obj, String name, void** outValue)
168 {
169 return dwt.internal.objc.bindings.object_getInstanceVariable(obj, name.ptr, outValue);
170 }
171
172 Ivar object_setInstanceVariable (id obj, String name, void* value)
173 {
174 return dwt.internal.objc.bindings.object_setInstanceVariable(obj, name.ptr, value);
175 }
176
177 SEL sel_registerName (String str)
178 {
179 return dwt.internal.objc.bindings.sel_registerName(str.ptr);
180 }
181
182 id objc_msgSend (ARGS...) (id theReceiver, SEL theSelector, ARGS args)
183 {
184 return dwt.internal.objc.bindings.objc_msgSend(theReceiver, theSelector, args);
185 }
186
187 void objc_msgSend_struct (T, ARGS...) (T* result, id theReceiver, SEL theSelector, ARGS args)
188 {
189 result = cast(T*) dwt.internal.objc.bindings.objc_msgSend(theReceiver, theSelector, args);
190 }
191
192 void objc_msgSend_stret (T, ARGS...) (out T stretAddr, id theReceiver, SEL theSelector, ARGS args)
193 {
194 dwt.internal.objc.bindings.objc_msgSend_stret(stretAddr, theReceiver, theSelector, args);
195 }
196
197 id objc_msgSendSuper (ARGS...) (objc_super* superr, SEL op, ARGS args)
198 {
199 return dwt.internal.objc.bindings.objc_msgSendSuper(superr, op, args);
200 }
201
202 bool objc_msgSend_bool (ARGS...) (id theReceiver, SEL theSelector, ARGS args)
203 {
204 return cast(bool) dwt.internal.objc.bindings.objc_msgSend(theReceiver, theSelector, args);
205 }
206
207 version (X86)
208 {
209 double objc_msgSend_fpret(ARGS...) (id self, SEL op, ARGS args)
210 {
211 return dwt.internal.objc.bindings.objc_msgSend_fpret(self, op, args);
113 } 212 }
114 } 213 }
115
116
117
118
119 alias dwt.internal.objc.bindings.objc_registerClassPair objc_registerClassPair;
120
121 bool class_addIvar (Class cls, String name, size_t size, byte alignment, String types)
122 {
123 return dwt.internal.objc.bindings.class_addIvar(cls, name.ptr, size, alignment, types.ptr);
124 }
125
126 bool class_addMethod (Class cls, String name, IMP imp, String types)
127 {
128 return dwt.internal.objc.bindings.class_addMethod(cls, name.ptr, imp, types.ptr);
129 }
130
131 Class objc_allocateClassPair (Class superclass, String name, size_t extraBytes)
132 {
133 return dwt.internal.objc.bindings.objc_allocateClassPair(superclass, name.ptr, extraBytes);
134 }
135
136 id objc_getClass (String name)
137 {
138 return dwt.internal.objc.bindings.objc_getClass(name.ptr);
139 }
140
141 id objc_lookUpClass (String name)
142 {
143 return dwt.internal.objc.bindings.objc_lookUpClass(name.ptr);
144 }
145
146 String object_getClassName (id obj)
147 {
148 return fromStringz(dwt.internal.objc.bindings.object_getClassName(obj));
149 }
150
151 Ivar object_getInstanceVariable (id obj, String name, void** outValue)
152 {
153 return dwt.internal.objc.bindings.object_getInstanceVariable(obj, name.ptr, outValue);
154 }
155
156 Ivar object_setInstanceVariable (id obj, String name, void* value)
157 {
158 return dwt.internal.objc.bindings.object_setInstanceVariable(obj, name.ptr, value);
159 }
160
161 String sel_registerName (String str)
162 {
163 return fromStringz(dwt.internal.objc.bindings.sel_registerName(str.ptr));
164 }
165
166 id objc_msgSend (ARGS...)(id theReceiver, String theSelector, ARGS args)
167 {
168 return dwt.internal.objc.bindings.objc_msgSend(theReceiver, theSelector.ptr, args);
169 }
170
171 void objc_msgSend_struct (T, ARGS...)(T* result, id theReceiver, String theSelector, ARGS args)
172 {
173 result = cast(T*) dwt.internal.objc.bindings.objc_msgSend(theReceiver, theSelector.ptr, args);
174 }
175
176 void objc_msgSend_stret (T, ARGS...)(T* stretAddr, id theReceiver, String theSelector, ARGS args)
177 {
178 dwt.internal.objc.bindings.objc_msgSend_stret(stretAddr, theReceiver, theSelector.ptr, args);
179 }
180
181 id objc_msgSendSuper (ARGS...)(objc_super* superr, String op, ARGS args)
182 {
183 return dwt.internal.objc.bindings.objc_msgSendSuper(superr, op.ptr, args);
184 }
185
186 version (X86)
187 {
188 double objc_msgSend_fpret(ARGS...)(id self, String op, ARGS args)
189 {
190 return dwt.internal.objc.bindings.objc_msgSend_fpret(self, op.ptr, args);
191 }
192 }
193
194
195 // os_custom
196 extern (C):
197 //alias void function (id, SEL, NSRect*) funcPtr;
198 static IMP drawRect_1CALLBACK;
199
200
201 private void drawRect(id obj, SEL sel, NSRect rect)
202 {
203 return cast(IMP) drawRect_1CALLBACK(obj, sel, &rect);
204 }
205
206 IMP drawRect_CALLBACK (IMP func)
207 {
208 drawRect_1CALLBACK = func;
209 return cast(IMP) &drawRect;
210 }