Mercurial > projects > dwt-mac
comparison dwt/internal/objc/runtime.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | 8b48be5454ce |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:380af2bdd8e5 |
---|---|
1 /** | |
2 * Copyright: Copyright (c) 2008 Jacob Carlborg. All rights reserved. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: 2008 | |
5 * License: $(LINK2 http://opensource.org/licenses/bsd-license.php, BSD Style) | |
6 * | |
7 */ | |
8 module dwt.internal.objc.runtime; | |
9 | |
10 import tango.stdc.stringz : fromStringz, toStringz; | |
11 | |
12 import dwt.dwthelper.utils : string; | |
13 static import dwt.internal.objc.bindings; | |
14 | |
15 alias objc_ivar* Ivar; | |
16 alias objc_method* Method; | |
17 alias objc_object Protocol; | |
18 | |
19 alias char* SEL; | |
20 alias objc_class* Class; | |
21 alias objc_object* id; | |
22 | |
23 alias extern (C) id function(id, SEL, ...) IMP; | |
24 | |
25 struct objc_object | |
26 { | |
27 Class isa; | |
28 } | |
29 | |
30 struct objc_super | |
31 { | |
32 id receiver; | |
33 Class clazz; | |
34 } | |
35 | |
36 struct objc_class | |
37 { | |
38 Class isa; | |
39 Class super_class; | |
40 const char* name; | |
41 int versionn; | |
42 int info; | |
43 int instance_size; | |
44 objc_ivar_list* ivars; | |
45 objc_method_list** methodLists; | |
46 objc_cache* cache; | |
47 objc_protocol_list* protocols; | |
48 } | |
49 | |
50 struct objc_ivar | |
51 { | |
52 char* ivar_name; | |
53 char* ivar_type; | |
54 int ivar_offset; | |
55 | |
56 version (X86_64) | |
57 int space; | |
58 } | |
59 | |
60 struct objc_ivar_list | |
61 { | |
62 int ivar_count; | |
63 | |
64 version (X86_64) | |
65 int space; | |
66 | |
67 /* variable length structure */ | |
68 objc_ivar ivar_list[1]; | |
69 } | |
70 | |
71 struct objc_method | |
72 { | |
73 SEL method_name; | |
74 char* method_types; | |
75 IMP method_imp; | |
76 } | |
77 | |
78 struct objc_method_list | |
79 { | |
80 objc_method_list* obsolete; | |
81 | |
82 int method_count; | |
83 | |
84 version (X86_64) | |
85 int space; | |
86 | |
87 /* variable length structure */ | |
88 objc_method method_list[1]; | |
89 } | |
90 | |
91 struct objc_cache | |
92 { | |
93 uint mask /* total = mask + 1 */; | |
94 uint occupied; | |
95 Method buckets[1]; | |
96 } | |
97 | |
98 struct objc_protocol_list | |
99 { | |
100 objc_protocol_list* next; | |
101 long count; | |
102 Protocol* list[1]; | |
103 } | |
104 | |
105 template Runtime () | |
106 { | |
107 alias dwt.internal.objc.bindings.objc_msgSendSuper objc_msgSendSuper; | |
108 alias dwt.internal.objc.bindings.objc_registerClassPair objc_registerClassPair; | |
109 alias dwt.internal.objc.bindings.objc_msgSend objc_msgSend; | |
110 alias dwt.internal.objc.bindings.objc_msgSend_fpret objc_msgSend_fpret; | |
111 alias dwt.internal.objc.bindings.objc_msgSend_stret objc_msgSend_stret; | |
112 | |
113 bool class_addIvar (Class cls, string name, size_t size, byte alignment, string types) | |
114 { | |
115 return dwt.internal.objc.bindings.class_addIvar(cls, name.toStringz(), size, alignment, types.toStringz()); | |
116 } | |
117 | |
118 bool class_addMethod (Class cls, SEL name, IMP imp, string types) | |
119 { | |
120 return dwt.internal.objc.bindings.class_addMethod(cls, name, imp, types.toStringz()); | |
121 } | |
122 | |
123 Class objc_allocateClassPair (Class superclass, string name, size_t extraBytes) | |
124 { | |
125 return dwt.internal.objc.bindings.objc_allocateClassPair(superclass, name.toStringz(), extraBytes); | |
126 } | |
127 | |
128 id objc_getClass (string name) | |
129 { | |
130 return dwt.internal.objc.bindings.objc_getClass(name.toStringz()); | |
131 } | |
132 | |
133 id objc_lookUpClass (string name) | |
134 { | |
135 return dwt.internal.objc.bindings.objc_lookUpClass(name.toStringz()); | |
136 } | |
137 | |
138 string object_getClassName (id obj) | |
139 { | |
140 return fromStringz(dwt.internal.objc.bindings.object_getClassName(obj)); | |
141 } | |
142 | |
143 Ivar object_getInstanceVariable (id obj, string name, void** outValue) | |
144 { | |
145 return dwt.internal.objc.bindings.object_getInstanceVariable(obj, name.toStringz(), outValue); | |
146 } | |
147 | |
148 Ivar object_setInstanceVariable (id obj, string name, void* value) | |
149 { | |
150 return dwt.internal.objc.bindings.object_setInstanceVariable(obj, name.toStringz(), value); | |
151 } | |
152 | |
153 string sel_registerName (string str) | |
154 { | |
155 return fromStringz(dwt.internal.objc.bindings.sel_registerName(str.toStringz())); | |
156 } | |
157 } |