Mercurial > projects > dstep
annotate dstep/objc/message.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | c0cfd40362ee |
children | b9de51448c6b |
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 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
38 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
|
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 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
46 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
|
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 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
52 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
|
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 { | |
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
|
102 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
|
103 return (cast(fp)&bindings.method_invoke)(receiver, m, args); |
1 | 104 } |
105 | |
106 void method_invoke_stret (ARGS...) (id receiver, Method m, ARGS args) | |
107 { | |
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
|
108 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
|
109 return (cast(fp)&bindings.method_invoke_stret)(receiver, m, args); |
1 | 110 } |
111 | |
112 R objc_msgSendv (R = id, T) (id self, SEL op, size_t arg_size, T arg_frame) | |
113 { | |
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
|
114 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
|
115 (cast(fp)&bindings.objc_msgSendv)(self, op, arg_size, arg_frame); |
1 | 116 } |
117 | |
118 void objc_msgSendv_stret (R = id, T) (out T stretAddr, id self, SEL op, size_t arg_size, T arg_frame) | |
119 { | |
120 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
|
121 { |
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
|
122 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
|
123 (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
|
124 } |
1 | 125 |
126 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
|
127 { |
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
|
128 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
|
129 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
|
130 } |
1 | 131 } |
132 | |
133 version (X86) | |
134 { | |
135 R objc_msgSendv_fpret (R = id, T) (id self, SEL op, uint arg_size, T arg_frame) | |
136 { | |
137 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
|
138 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
|
139 return (cast(fp)&bindings.objc_msgSendv_fpret)(self, op, arg_size, arg_frame); |
1 | 140 } |
141 } |