Mercurial > projects > dstep
comparison dstep/objc/message.d @ 1:033d260cfc9b
First upload of the bridge
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Thu, 18 Jun 2009 22:00:13 +0200 |
parents | |
children | c0cfd40362ee |
comparison
equal
deleted
inserted
replaced
0:c7db221de6e8 | 1:033d260cfc9b |
---|---|
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 { | |
38 return (cast(R function (id, SEL, ARGS...))&bindings.objc_msgSendSuper)(this, op, args); | |
39 } | |
40 | |
41 void msgSendSuper_stret (T, ARGS...) (out T stretAddr, id self, SEL op, ARGS args) | |
42 { | |
43 if (T.sizeof > STRUCT_SIZE_LIMIT) | |
44 (cast(void function (T*, id, SEL, ARGS...))&bindings.objc_msgSendSuper_stret)(&stretAddr, self, op, args); | |
45 | |
46 else | |
47 stretAddr = (*cast(T function (id, SEL, ARGS...))&bindings.objc_msgSendSuper)(self, op, args); | |
48 } | |
49 } | |
50 | |
51 R objc_msgSend (R = id, ARGS...) (id self, SEL op, ARGS args) | |
52 { | |
53 return (cast(R function (id, SEL, ARGS...))&bindings.objc_msgSend)(self, op, args); | |
54 } | |
55 | |
56 R objc_msgSendSuper (R = id, ARGS...) (objc_super* super_, SEL op, ARGS args) | |
57 { | |
58 return (cast(R function (id, SEL, ARGS...))&bindings.objc_msgSendSuper)(super_, op, args); | |
59 } | |
60 | |
61 void objc_msgSend_stret (T, ARGS...) (out T stretAddr, id self, SEL op, ARGS args) | |
62 { | |
63 if (T.sizeof > STRUCT_SIZE_LIMIT) | |
64 (cast(void function (T*, id, SEL, ARGS...))&bindings.objc_msgSend_stret)(&stretAddr, self, op, args); | |
65 | |
66 else | |
67 stretAddr = (*cast(T function (id, SEL, ARGS...))&bindings.objc_msgSend)(self, op, args); | |
68 } | |
69 | |
70 static if (X86 || X86_64) | |
71 { | |
72 R objc_msgSend_fpret (R = id, ARGS...) (id self, SEL op, ARGS args) | |
73 { | |
74 version (X86_64) | |
75 static assert(!is(R : real), "Only real are legal return value for objc_msgSend_fpret"); | |
76 | |
77 else | |
78 static assert(!is(R : double) && !is(R : float), "Only double and float are legal return values for objc_msgSend_fpret"); | |
79 | |
80 return (cast(R function (id, SEL, ARGS...))&bindings.objc_msgSend_fpret)(self, op, args); | |
81 } | |
82 } | |
83 | |
84 R method_invoke (R = id, ARGS...) (id receiver, Method m, ARGS args) | |
85 { | |
86 static assert(receiver !is null); | |
87 return (cast(R function (id, SEL, ARGS...))&bindings.method_invoke)(receiver, m, args); | |
88 } | |
89 | |
90 void method_invoke_stret (ARGS...) (id receiver, Method m, ARGS args) | |
91 { | |
92 static assert(receiver !is null); | |
93 return (cast(R function (id, SEL, ARGS...))&bindings.method_invoke_stret)(receiver, m, args); | |
94 } | |
95 | |
96 R objc_msgSendv (R = id, T) (id self, SEL op, size_t arg_size, T arg_frame) | |
97 { | |
98 (cast(R function (id, SEL, size_t, T))&bindings.objc_msgSendv)(self, op, arg_size, arg_frame); | |
99 } | |
100 | |
101 void objc_msgSendv_stret (R = id, T) (out T stretAddr, id self, SEL op, size_t arg_size, T arg_frame) | |
102 { | |
103 if (R.sizeof > STRUCT_SIZE_LIMIT) | |
104 (cast(void function (R*, id, SEL, size_t, T))&bindings.objc_msgSendv_stret)(&stretAddr, self, op, arg_size, arg_frame); | |
105 | |
106 else | |
107 stretAddr = (*cast(R function (id, SEL, size_t, T))&bindings.objc_msgSendv)(self, op, arg_size, arg_frame); | |
108 } | |
109 | |
110 version (X86) | |
111 { | |
112 R objc_msgSendv_fpret (R = id, T) (id self, SEL op, uint arg_size, T arg_frame) | |
113 { | |
114 static assert(!is(R : double) && !is(R : float), "Only double and float are legal return values for objc_msgSendv_fpret"); | |
115 return (cast(R function (id, SEL, uint, T))&bindings.objc_msgSendv_fpret)(self, op, arg_size, arg_frame); | |
116 } | |
117 } |