digitalmars.D - D calling convention
- Christian Kamm (25/25) Oct 28 2008 Tomas has done a lot of work on D ABI compatibility for LDC during the l...
- Jarrett Billingsley (3/28) Oct 28 2008 All of these things would make me happy. :)
- Walter Bright (6/12) Oct 28 2008 The reason is because I'd eventually like to specify the order of
- Tomas Lindquist Olsen (6/19) Oct 28 2008 What do you think of the "proposal"?, I think it could be quite valuable...
- Jason House (2/15) Oct 28 2008 It's sounding like right-to-left makes more sense than left-to-right. A...
- Walter Bright (6/11) Oct 28 2008 People intuitively expect expressions to be evaluated left-to-right, and...
- Christian Kamm (9/21) Oct 28 2008 What about generally passing left-to-right for D functions then?
- Walter Bright (3/7) Oct 29 2008 EAX always gets the last argument evaluated, because evaluating an
- Christian Kamm (3/5) Oct 29 2008 Ah, right. I didn't think of that.
- Walter Bright (2/5) Oct 29 2008 I don't think it's worth it. Passing it in EAX is a big performance win.
- Lionello Lunesu (4/16) Oct 28 2008 Is it possible to solve this problem and also solve the problem mentione...
- Christian Kamm (2/5) Oct 28 2008 The two things are separate. Delegates are functions that have the conte...
- Lionello Lunesu (9/14) Oct 29 2008 But it matters how delegates pass the context pointer. In order to call
- Tomas Lindquist Olsen (11/33) Oct 29 2008 As I see it there are really 3 different scenarios we'd (do we?) like to...
Tomas has done a lot of work on D ABI compatibility for LDC during the last weeks. He's come quite far: except for the passing of some parameters in EAX, things seem to work fine. One point we couldn't understand though, is the reversal of parameters when calling some D functions: Parameters are usually passed right-to-left, except for nonvariadic D functions, where the order changes to left-to-right. What is the reason for it? If this was not so, and D functions would always pass parameters right-to-left, it'd be very easy to call a member or nested function given the type and address only: the context would just always go first in the parameter list (and hence be passed last, possibly in EAX). As it is, you have to put the context in as the last argument - except for variadics, where it can go first again. As a somewhat related, but separate issue, this would open the door to real easy pointer-to-members. Given class C { void foo(int i) { ... } } you could have typeof(C.foo) == void function(C, int) and auto memberfn = &C.foo; memberfn(new C, 42); would work too.
Oct 28 2008
On Tue, Oct 28, 2008 at 12:28 PM, Christian Kamm <kamm-incasoftware removethis.de> wrote:Tomas has done a lot of work on D ABI compatibility for LDC during the last weeks. He's come quite far: except for the passing of some parameters in EAX, things seem to work fine. One point we couldn't understand though, is the reversal of parameters when calling some D functions: Parameters are usually passed right-to-left, except for nonvariadic D functions, where the order changes to left-to-right. What is the reason for it? If this was not so, and D functions would always pass parameters right-to-left, it'd be very easy to call a member or nested function given the type and address only: the context would just always go first in the parameter list (and hence be passed last, possibly in EAX). As it is, you have to put the context in as the last argument - except for variadics, where it can go first again. As a somewhat related, but separate issue, this would open the door to real easy pointer-to-members. Given class C { void foo(int i) { ... } } you could have typeof(C.foo) == void function(C, int) and auto memberfn = &C.foo; memberfn(new C, 42); would work too.All of these things would make me happy. :)
Oct 28 2008
Christian Kamm wrote:One point we couldn't understand though, is the reversal of parameters when calling some D functions: Parameters are usually passed right-to-left, except for nonvariadic D functions, where the order changes to left-to-right. What is the reason for it?The reason is because I'd eventually like to specify the order of evaluation of function arguments as being left to right. So, for normal D functions, this makes for optimal code generation. The only time monkey business would have to happen would be to support the C calling convention or the variadic one.
Oct 28 2008
Walter Bright wrote:Christian Kamm wrote:What do you think of the "proposal"?, I think it could be quite valuable and the current setup makes has some odd behaviour. Take the TypeInfo_Struct.xopCmp for example. Here a member function pointer is assigned to a static function pointer, the result being that you have to call it with parameters reversed for things to work as you expect, but only when x86 ABI is in effect.One point we couldn't understand though, is the reversal of parameters when calling some D functions: Parameters are usually passed right-to-left, except for nonvariadic D functions, where the order changes to left-to-right. What is the reason for it?The reason is because I'd eventually like to specify the order of evaluation of function arguments as being left to right. So, for normal D functions, this makes for optimal code generation. The only time monkey business would have to happen would be to support the C calling convention or the variadic one.
Oct 28 2008
Walter Bright Wrote:Christian Kamm wrote:It's sounding like right-to-left makes more sense than left-to-right. As an English speaker, left-to-right seems more natural, but I see no reason to require it. Beyond that, do we really want to require an evaluation order of arguments? I'd much prefer for the compiler to work its optimization magic than have a set order anyway.One point we couldn't understand though, is the reversal of parameters when calling some D functions: Parameters are usually passed right-to-left, except for nonvariadic D functions, where the order changes to left-to-right. What is the reason for it?The reason is because I'd eventually like to specify the order of evaluation of function arguments as being left to right. So, for normal D functions, this makes for optimal code generation. The only time monkey business would have to happen would be to support the C calling convention or the variadic one.
Oct 28 2008
Jason House wrote:It's sounding like right-to-left makes more sense than left-to-right. As an English speaker, left-to-right seems more natural, but I see no reason to require it. Beyond that, do we really want to require an evaluation order of arguments? I'd much prefer for the compiler to work its optimization magic than have a set order anyway.People intuitively expect expressions to be evaluated left-to-right, and that applies to function arguments, too. Eliminating implementation defined behavior makes the source code much more portable. There is no way to reliably detect inadvertent order-of-evaluation dependencies.
Oct 28 2008
Christian Kamm wrote:Walter Bright wrote:One point we couldn't understand though, is the reversal of parameters when calling some D functions: Parameters are usually passed right-to-left, except for nonvariadic D functions, where the order changes to left-to-right. What is the reason for it?The reason is because I'd eventually like to specify the order of evaluation of function arguments as being left to right. So, for normal D functions, this makes for optimal code generation. The only time monkey business would have to happen would be to support the C calling convention or the variadic one.What about generally passing left-to-right for D functions then? If foo(a1,...,an) was passed as (this), a1, ..., an, (_arguments), (hidden) with the first parameter in EAX if possible, we'd have the neatness of "member function pointers have context as first arg" and the possibility of specifying left-to-right evaluation order easily. We'd lose the ability to pass hidden in EAX though.
Oct 28 2008
Christian Kamm wrote:with the first parameter in EAX if possible, we'd have the neatness of "member function pointers have context as first arg" and the possibility of specifying left-to-right evaluation order easily. We'd lose the ability to pass hidden in EAX though.EAX always gets the last argument evaluated, because evaluating an expression often naturally winds up in EAX.
Oct 29 2008
Walter Bright Wrote:EAX always gets the last argument evaluated, because evaluating an expression often naturally winds up in EAX.Ah, right. I didn't think of that. Do I understand correctly that in order to get the 'context as the first arg' behavior, we'd have to drop either EAX or left-to-right passing? Maybe it's not worth it then.
Oct 29 2008
Christian Kamm wrote:Do I understand correctly that in order to get the 'context as the first arg' behavior, we'd have to drop either EAX or left-to-right passing? Maybe it's not worth it then.I don't think it's worth it. Passing it in EAX is a big performance win.
Oct 29 2008
As a somewhat related, but separate issue, this would open the door to real easy pointer-to-members. Given class C { void foo(int i) { ... } } you could have typeof(C.foo) == void function(C, int) and auto memberfn = &C.foo; memberfn(new C, 42); would work too.Is it possible to solve this problem and also solve the problem mentioned in the thread "implicitly convert function pointers to delegates"? Or are these two mutually exclusive? L.
Oct 28 2008
Is it possible to solve this problem and also solve the problem mentioned in the thread "implicitly convert function pointers to delegates"? Or are these two mutually exclusive?The two things are separate. Delegates are functions that have the context argument bound. This is about the passing order of arguments.
Oct 28 2008
"Christian Kamm" <kamm-incasoftware removethis.de> wrote in message news:ge9044$1l0d$1 digitalmars.com...But it matters how delegates pass the context pointer. In order to call functions using a delegate, the functions should silently ignore the context pointer. Which means they should never expect any argument to be passed in that register, or accept an argument on the stack that can be ignore (last one?).. I don't know the details, but I think these two issue are very closely related. L.Is it possible to solve this problem and also solve the problem mentioned in the thread "implicitly convert function pointers to delegates"? Or are these two mutually exclusive?The two things are separate. Delegates are functions that have the context argument bound. This is about the passing order of arguments.
Oct 29 2008
Lionello Lunesu wrote:"Christian Kamm" <kamm-incasoftware removethis.de> wrote in message news:ge9044$1l0d$1 digitalmars.com...As I see it there are really 3 different scenarios we'd (do we?) like to support: 1) converting a function pointer to a delegate 2) converting a member function pointer to a function pointer 3) converting a delegate to a function pointer 1) seems to be easiest by having the compiler generate a small wrapper that takes care of the differences in number of arguments. 2) would be easy to solve given the stuff mentioned in this thread 3) isn't really hard to solve either, at least in terms of LDC (thus LLVM), you'd just generate a trampoline.But it matters how delegates pass the context pointer. In order to call functions using a delegate, the functions should silently ignore the context pointer. Which means they should never expect any argument to be passed in that register, or accept an argument on the stack that can be ignore (last one?).. I don't know the details, but I think these two issue are very closely related. L.Is it possible to solve this problem and also solve the problem mentioned in the thread "implicitly convert function pointers to delegates"? Or are these two mutually exclusive?The two things are separate. Delegates are functions that have the context argument bound. This is about the passing order of arguments.
Oct 29 2008