Advertisement

Is there a less hacky way to get the D ABI working with AngelScript?

Started by November 10, 2020 04:46 AM
2 comments, last by Clipsey 4 years ago

I'm working on making an AngelScript binding for D with support for D types and functions. D's documentation says that it follows the C ABI for function calls, but in reality the int registers are reversed.

I made a really ugly hack to as_callfunc_x64_gcc.cpp which consists of reversing the order of int register arguments if a DDECL ABI is specified ( https://github.com/KitsunebiGames/angelscript-ddecl/blob/main/source/as_callfunc_x64_gcc.cpp#L449​ )

if (callConv == ICC_DDECL ||
	callConv == ICC_DDECL_RETURNINMEM ||
	callConv == ICC_DDECL_OBJFIRST ||
	callConv == ICC_DDECL_OBJFIRST_RETURNINMEM ||
	callConv == ICC_DDECL_OBJLAST ||
	callConv == ICC_DDECL_OBJLAST_RETURNINMEM) {
	
	// Handle DDECL arguments in a really cursed way
	// Can someone fix the D ABI, please????
	for ( n = totalArgumentCount-1; ( n >= 0 ) && ( used_int_regs < MAX_CALL_INT_REGISTERS ); n-- )
	{
		if ( argsType[n] == x64INTARG )
		{
			argsSet[n] = 1;
			tempBuff[idx++] = paramBuffer[n];
			used_int_regs++;
		}
	}
} else {
	// The normal way any sane ABI spec would do
	for ( n = 0; ( n < totalArgumentCount ) && ( used_int_regs < MAX_CALL_INT_REGISTERS ); n++ )
	{
		if ( argsType[n] == x64INTARG )
		{
			argsSet[n] = 1;
			tempBuff[idx++] = paramBuffer[n];
			used_int_regs++;
		}
	}
}

Does AngelScript support a less hacky way to add support for these reversed int registers?

None

I'm afraid not. But I'll take a closer look at your changes when I get the time.

I'm surprised to learn about this. It would mean D isn't really ABI compatible with C as it claims to be. Could it perhaps be a bug in the D compiler you're using?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

It is in fact a bug, but due to that just being a part of the D ABI the main D developers have decided to keep the “broken” ABI so that it doesn't break backwards compatibility.

My changes amount to reversing the int argument array when the ICC calling convention is any of the newly added ICC_DDECL types.

If you want to look through the D binding itself as well, here it is: https://github.com/KitsunebiGames/dangel

Sidenote: D is ABI compatible with C calling convention wise if you use extern(C), granted this makes large parts of D's nice features unusable. Which requires writing large wrappers around stuff like classes which are a mess to maintain.

None

This topic is closed to new replies.

Advertisement