reflection / D's function calling convention?

Jarrett Billingsley kb3ctd2 at yahoo.com
Wed Nov 1 06:52:57 PST 2006


"Chris Miller" <chris at dprogramming.com> wrote in message 
news:op.tib3szvnpo9bzi at tanu...
> Can you please explain some more...

Here's all that I've researched:

DMD FUNCTION CALLING CONVENTION:

params are passed, in general, l-to-r.

in functions with varargs, all params are passed r-to-l, and are all pushed.
varargs also push the _arguments array as the last (furthest left) param.
caller is responsible for cleaning up params to vararg function.

typesafe variadic functions just take an array as their variadic arg; the 
array is
built by the caller and passed as a regular array - because it's basically
a non-vararg function, params are passed l-to-r.

all kinds of ints, pointers, class refs, bools, char, wchar, dchar, func 
pointers:
 if not last, push; else, put in EAX

longs:
 push hi, push lo

float, ifloat:
 push

double, idouble:
 push hi, push lo

real, ireal:
 push really hi, push hi, push lo

cfloat:
 push float im, push float re

cdouble:
 push double im, push double re

creal:
 push real im, push real re

arrays:
 push pointer (hi), push length (lo)

delegates:
 push address, push context ptr ('this' or frame ptr)

structs:
 push the whole damn thing, starting at the beginning

D METHOD CALLING CONVENTION:

Similar to above, with following differences:

all kinds of ints, ptrs, refs etc:
 push

'this' goes into EAX

D DELEGATE CALLING CONVENTION:

put context in both EAX and EBX -- EBX is not actually used in the delegate 
though
put address in EDX
call EDX

> For variadic functions, the caller probably cleans up and the last arg not 
> put in EAX.

Right.

> What if the last arg does not fit in EAX; e.g. a char[], is half put in 
> EAX / half on the stack, or all on the stack?

It's pushed entirely.

> Return value: EAX, or also I believe EAX and EDX for 64-bit values.

I'm pretty sure longs are put in EDX:EAX as you say.

> Returning floating point: in floating point register?

Ooh, not sure about that one.

> Bigger return types probably first push a pointer to a return buffer?

Hmm, guess I didn't do much return type research :S

> Variadic TypeInfo[] _arguments pushed last or first or something else?

It's pushed last, so it's technically the furthest-left param (before all 
other params). 





More information about the Digitalmars-d mailing list