Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why compilers are retarded

Name: Cudder !MhMRSATORI 2014-09-09 4:38

Suppose I have a set of functions, written in Asm, which take as input parameters in registers, and also output multiple values in registers. In C, this would look like

struct { int n; char *e; char *f; }
phoo(int ni, void *p, char *ei, char *fi);


which is nothing special, but the problem is that no compiler I know of will allow specifying where the parameters and returns are!! They all only support a very limited set of "calling conventions", and nothing else. There's no way to write something like

struct { int n@eax; char *e@esi; char *f@edi; }
phoo(int ni@ecx, void *p@edx, char *ei@esi, char *fi@edi);


and have existing compilers generate the appropriate code when calling and using the return values. Is it really so hard to, when compiling a function call,

1. Look up where the function wants its parameters
2. Evaluate the parameters and put them in the right places
3. Call the function
4. Direct any expressions using its the return value(s) to read from the right places

instead of following a stupid cookie-cutter template every time? Am I going to have to write a compiler too?

As they say, "If you want it done right, do it yourself..."

Name: Anonymous 2014-09-10 5:56

>>1
The Watcom C and C++ compilers did allow the calling convention to be customized using the magic #pragma aux:

http://www.openwatcom.org/index.php/Calling_Conventions#Specifying_Calling_Conventions_the_Watcom_Way

There are some limitations, mostly involving composite data types that can only be passed in certain registers or register pairs. I never managed to find the code in the OpenWatcom tree that handles this but I suspect it involves some highly involved fiddling with the code generator's naughty bits.

Whatever the implementation, it works pretty well for its primary purpose (interfacing with baroque DOS TSR and BIOS interrupt services).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List