Mercurial > projects > dstep
annotate dstep/objc/message.d @ 6:c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 08 Jul 2009 14:29:59 +0200 |
parents | 033d260cfc9b |
children | 19885b43130e |
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 | |
28 struct objc_super | |
29 { | |
30 id receiver; | |
31 Class super_class; | |
32 | |
33 // for dwt compatibility | |
34 alias super_class cls; | |
35 | |
36 R msgSendSuper (R = id, ARGS...) (SEL op, ARGS args) | |
37 { | |
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
|
38 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
|
39 return (cast(fp)&bindings.objc_msgSendSuper)(this, op, args); |
1 | 40 } |
41 | |
42 void msgSendSuper_stret (T, ARGS...) (out T stretAddr, id self, SEL op, ARGS args) | |
43 { | |
44 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
|
45 { |
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
|
46 alias extern (C) void function (T*, 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
|
47 (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
|
48 } |
1 | 49 |
50 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
|
51 { |
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
|
52 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
|
53 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
|
54 } |
1 | 55 } |
56 } | |
57 | |
58 R objc_msgSend (R = id, ARGS...) (id self, SEL op, ARGS args) | |
59 { | |
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
|
60 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
|
61 return (cast(fp)&bindings.objc_msgSend)(self, op, args); |
1 | 62 } |
63 | |
64 R objc_msgSendSuper (R = id, ARGS...) (objc_super* super_, SEL op, ARGS args) | |
65 { | |
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
|
66 alias extern(C) R function (objc_super*, 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
|
67 return (cast(fp)&bindings.objc_msgSendSuper)(super_, op, args); |
1 | 68 } |
69 | |
70 void objc_msgSend_stret (T, ARGS...) (out T stretAddr, id self, SEL op, ARGS args) | |
71 { | |
72 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
|
73 { |
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
|
74 alias extern(C) void function (T*, 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
|
75 (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
|
76 } |
1 | 77 |
78 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
|
79 { |
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
|
80 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
|
81 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
|
82 } |
1 | 83 } |
84 | |
85 static if (X86 || X86_64) | |
86 { | |
87 R objc_msgSend_fpret (R = id, ARGS...) (id self, SEL op, ARGS args) | |
88 { | |
89 version (X86_64) | |
90 static assert(!is(R : real), "Only real are legal return value for objc_msgSend_fpret"); | |
91 | |
92 else | |
93 static assert(!is(R : double) && !is(R : float), "Only double and float are legal return values for objc_msgSend_fpret"); | |
94 | |
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 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
|
96 return (cast(fp)&bindings.objc_msgSend_fpret)(self, op, args); |
1 | 97 } |
98 } | |
99 | |
100 R method_invoke (R = id, ARGS...) (id receiver, Method m, ARGS args) | |
101 { | |
102 static assert(receiver !is null); | |
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
|
103 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
|
104 return (cast(fp)&bindings.method_invoke)(receiver, m, args); |
1 | 105 } |
106 | |
107 void method_invoke_stret (ARGS...) (id receiver, Method m, ARGS args) | |
108 { | |
109 static assert(receiver !is null); | |
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
|
110 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
|
111 return (cast(fp)&bindings.method_invoke_stret)(receiver, m, args); |
1 | 112 } |
113 | |
114 R objc_msgSendv (R = id, T) (id self, SEL op, size_t arg_size, T arg_frame) | |
115 { | |
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
|
116 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
|
117 (cast(fp)&bindings.objc_msgSendv)(self, op, arg_size, arg_frame); |
1 | 118 } |
119 | |
120 void objc_msgSendv_stret (R = id, T) (out T stretAddr, id self, SEL op, size_t arg_size, T arg_frame) | |
121 { | |
122 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
|
123 { |
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) 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
|
125 (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
|
126 } |
1 | 127 |
128 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
|
129 { |
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 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
|
132 } |
1 | 133 } |
134 | |
135 version (X86) | |
136 { | |
137 R objc_msgSendv_fpret (R = id, T) (id self, SEL op, uint arg_size, T arg_frame) | |
138 { | |
139 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
|
140 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
|
141 return (cast(fp)&bindings.objc_msgSendv_fpret)(self, op, arg_size, arg_frame); |
1 | 142 } |
143 } |