Mercurial > projects > dstep
annotate dstep/objc/message.d @ 27:57371c29ef73 default tip
ObjcWrap is now automatically mixed in. Added support for building as a dylib with DMD.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 09 Apr 2010 23:00:22 +0200 |
parents | b9de51448c6b |
children |
rev | line source |
---|---|
1 | 1 /** |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Feb 1, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.objc.message; | |
8 | |
9 import dstep.internal.Version; | |
10 import bindings = dstep.objc.bindings; | |
11 import dstep.objc.objc; | |
12 import dstep.objc.runtime; | |
13 | |
14 alias void* marg_list; | |
15 | |
16 version (X86) | |
17 const int STRUCT_SIZE_LIMIT = 8; | |
18 | |
19 else version (PPC) | |
20 const int STRUCT_SIZE_LIMIT = 4; | |
21 | |
22 else version (X86_64) | |
23 const int STRUCT_SIZE_LIMIT = 16; | |
24 | |
25 else version (PPC64) // Not sure about this | |
26 const int STRUCT_SIZE_LIMIT = 16; | |
27 | |
25
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
28 /** |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
29 * Specifies the superclass of an instance. |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
30 * |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
31 * The compiler generates an objc_super data structure when it encounters the super |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
32 * keyword as the receiver of a message. It specifies the class definition of the |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
33 * particular superclass that should be messaged. |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
34 */ |
1 | 35 struct objc_super |
36 { | |
25
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
37 /** |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
38 * A pointer of type $(DSTEP_EXTERNAL_SYMBOL dstep.objc.objc, id). |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
39 * Specifies an instance of a class. |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
40 */ |
1 | 41 id receiver; |
25
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
42 |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
43 /** |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
44 * A pointer to an $(DIL_EXTERNAL_SYMBOL dstep.objc.objc, Class) data |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
45 * structure. Specifies the particular superclass of the instance to message. |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
46 */ |
1 | 47 Class super_class; |
48 | |
49 // for dwt compatibility | |
50 alias super_class cls; | |
51 | |
52 R msgSendSuper (R = id, ARGS...) (SEL op, ARGS args) | |
53 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
54 alias extern (C) R function (objc_super*, SEL, ARGS) fp; |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
55 return (cast(fp)&bindings.objc_msgSendSuper)(this, op, args); |
1 | 56 } |
57 | |
58 void msgSendSuper_stret (T, ARGS...) (out T stretAddr, id self, SEL op, ARGS args) | |
59 { | |
60 if (T.sizeof > STRUCT_SIZE_LIMIT) | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
61 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
62 alias extern (C) void function (T*, objc_super*, SEL, ARGS) fp; |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
63 (cast(fp)&bindings.objc_msgSendSuper_stret)(&stretAddr, self, op, args); |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
64 } |
1 | 65 |
66 else | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
67 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
68 alias extern (C) T function (objc_super*, SEL, ARGS) fp; |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
69 stretAddr = (*cast(fp)&bindings.objc_msgSendSuper)(self, op, args); |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
70 } |
1 | 71 } |
72 } | |
73 | |
74 R objc_msgSend (R = id, ARGS...) (id self, SEL op, ARGS args) | |
75 { | |
25
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
76 alias extern (C) R function (id, SEL, ARGS) fp; |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
77 return (cast(fp)&bindings.objc_msgSend)(self, op, args); |
1 | 78 } |
79 | |
80 R objc_msgSendSuper (R = id, ARGS...) (objc_super* super_, SEL op, ARGS args) | |
81 { | |
25
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
82 alias extern (C) R function (objc_super*, SEL, ARGS) fp; |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
83 return (cast(fp)&bindings.objc_msgSendSuper)(super_, op, args); |
1 | 84 } |
85 | |
86 void objc_msgSend_stret (T, ARGS...) (out T stretAddr, id self, SEL op, ARGS args) | |
87 { | |
88 if (T.sizeof > STRUCT_SIZE_LIMIT) | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
89 { |
25
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
90 alias extern (C) void function (T*, id, SEL, ARGS) fp; |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
91 (cast(void function (fp))&bindings.objc_msgSend_stret)(&stretAddr, self, op, args); |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
92 } |
1 | 93 |
94 else | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
95 { |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
96 alias extern (C) T function (id, SEL, ARGS) fp; |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
97 stretAddr = (*cast(fp)&bindings.objc_msgSend)(self, op, args); |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
98 } |
1 | 99 } |
100 | |
101 static if (X86 || X86_64) | |
102 { | |
103 R objc_msgSend_fpret (R = id, ARGS...) (id self, SEL op, ARGS args) | |
104 { | |
105 version (X86_64) | |
106 static assert(!is(R : real), "Only real are legal return value for objc_msgSend_fpret"); | |
107 | |
108 else | |
109 static assert(!is(R : double) && !is(R : float), "Only double and float are legal return values for objc_msgSend_fpret"); | |
110 | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
111 alias extern (C) R function (id, SEL, ARGS) fp; |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
112 return (cast(fp)&bindings.objc_msgSend_fpret)(self, op, args); |
1 | 113 } |
114 } | |
115 | |
116 R method_invoke (R = id, ARGS...) (id receiver, Method m, ARGS args) | |
117 { | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
118 alias extern (C) R function (id, SEL, ARGS) fp; |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
119 return (cast(fp)&bindings.method_invoke)(receiver, m, args); |
1 | 120 } |
121 | |
122 void method_invoke_stret (ARGS...) (id receiver, Method m, ARGS args) | |
123 { | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
124 alias extern (C) R function (id, SEL, ARGS) fp; |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
125 return (cast(fp)&bindings.method_invoke_stret)(receiver, m, args); |
1 | 126 } |
127 | |
128 R objc_msgSendv (R = id, T) (id self, SEL op, size_t arg_size, T arg_frame) | |
129 { | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
130 alias extern (C) R function (id, SEL, size_t, T) fp; |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
131 (cast(fp)&bindings.objc_msgSendv)(self, op, arg_size, arg_frame); |
1 | 132 } |
133 | |
134 void objc_msgSendv_stret (R = id, T) (out T stretAddr, id self, SEL op, size_t arg_size, T arg_frame) | |
135 { | |
136 if (R.sizeof > STRUCT_SIZE_LIMIT) | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
137 { |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
138 alias extern (C) void function (R*, id, SEL, size_t, T) fp; |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
139 (cast(fp)&bindings.objc_msgSendv_stret)(&stretAddr, self, op, arg_size, arg_frame); |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
140 } |
1 | 141 |
142 else | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
143 { |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
144 alias extern (C) R function (id, SEL, size_t, T) fp; |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
145 stretAddr = (*cast(fp)&bindings.objc_msgSendv)(self, op, arg_size, arg_frame); |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
146 } |
1 | 147 } |
148 | |
149 version (X86) | |
150 { | |
151 R objc_msgSendv_fpret (R = id, T) (id self, SEL op, uint arg_size, T arg_frame) | |
152 { | |
153 static assert(!is(R : double) && !is(R : float), "Only double and float are legal return values for objc_msgSendv_fpret"); | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
154 alias extern (C) R function (id, SEL, uint, T) fp; |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
155 return (cast(fp)&bindings.objc_msgSendv_fpret)(self, op, arg_size, arg_frame); |
1 | 156 } |
157 } |