D Application Binary Interface
A D implementation that conforms to the D ABI (Application Binary Interface) will be able to generate libraries, DLL's, etc., that can interoperate with D binaries built by other implementations.
C ABI
The C ABI referred to in this specification means the C Application Binary Interface of the target system. C and D code should be freely linkable together, in particular, D code shall have access to the entire C ABI runtime library.
Endianness
The endianness (byte order) of the layout of the data will conform to the endianness of the target machine. The Intel x86 CPUs are little endian meaning that the value 0x0A0B0C0D is stored in memory as: 0D 0C 0B 0A.
Basic Types
- bool
- 8 bit byte with the values 0 for false and 1 for true
- byte
- 8 bit signed value
- ubyte
- 8 bit unsigned value
- short
- 16 bit signed value
- ushort
- 16 bit unsigned value
- int
- 32 bit signed value
- uint
- 32 bit unsigned value
- long
- 64 bit signed value
- ulong
- 64 bit unsigned value
- cent
- 128 bit signed value
- ucent
- 128 bit unsigned value
- float
- 32 bit IEEE 754 floating point value
- double
- 64 bit IEEE 754 floating point value
- real
- implementation defined floating point value, for x86 it is 80 bit IEEE 754 extended real
Delegates
Delegates are fat pointers with two parts:
| offset | property | contents |
|---|---|---|
| 0 | .ptr | context pointer |
| ptrsize | .funcptr | pointer to function |
The context pointer can be a class this reference, a struct this pointer, a pointer to a closure (nested functions) or a pointer to an enclosing function's stack frame (nested functions).
Structs
Conforms to the target's C ABI struct layout.
Classes
An object consists of:
| offset | property | contents |
|---|---|---|
| 0 | .__vptr | pointer to vtable |
| ptrsize | .__monitor | monitor |
| ptrsize*2... | named members | non-static members |
The vtable consists of:
| offset | contents |
|---|---|
| 0 | pointer to instance of ClassInfo |
| ptrsize... | pointers to virtual member functions |
The class definition:
class XXXX
{
....
};
Generates the following:
- An instance of Class called ClassXXXX.
- A type called StaticClassXXXX which defines all the static members.
- An instance of StaticClassXXXX called StaticXXXX for the static members.
Interfaces
An interface is a pointer to a pointer to a vtbl[]. The vtbl[0] entry is a pointer to the corresponding instance of the object.Interface class. The rest of the vtbl[1..$] entries are pointers to the virtual functions implemented by that interface, in the order that they were declared.
A COM interface differs from a regular interface in that there is no object.Interface entry in vtbl[0]; the entries vtbl[0..$] are all the virtual function pointers, in the order that they were declared. This matches the COM object layout used by Windows.
A C++ interface differs from a regular interface in that it matches the layout of a C++ class using single inheritance on the target machine.
Arrays
A dynamic array consists of:
| offset | property | contents |
|---|---|---|
| 0 | .length | array dimension |
| size_t | .ptr | pointer to array data |
A dynamic array is declared as:
type[] array;
whereas a static array is declared as:
type[dimension] array;
Thus, a static array always has the dimension statically available as part of the type, and so it is implemented like in C. Static array's and Dynamic arrays can be easily converted back and forth to each other.
Associative Arrays
Associative arrays consist of a pointer to an opaque, implementation defined type. The current implementation is contained in phobos/internal/aaA.d.
Reference Types
D has reference types, but they are implicit. For example, classes are always referred to by reference; this means that class instances can never reside on the stack or be passed as function parameters.
When passing a static array to a function, the result, although declared as a static array, will actually be a reference to a static array. For example:
int[3] abc;
Passing abc to functions results in these implicit conversions:
void func(int[3] array); // actually <reference to><array[3] of><int> void func(int* p); // abc is converted to a pointer // to the first element void func(int[] array); // abc is converted to a dynamic array
Name Mangling
D accomplishes typesafe linking by mangling a D identifier to include scope and type information.
MangledName:
_D QualifiedName Type
_D QualifiedName M Type
QualifiedName:
SymbolName
SymbolName QualifiedName
SymbolName:
LName
TemplateInstanceName
The M means that the symbol is a function that requires a this pointer.
Template Instance Names have the types and values of its parameters encoded into it:
TemplateInstanceName:
__T LName TemplateArgs Z
TemplateArgs:
TemplateArg
TemplateArg TemplateArgs
TemplateArg:
T Type
V Type Value
S LName
Value:
n
Number
N Number
e HexFloat
c HexFloat c HexFloat
A Number Value...
HexFloat:
NAN
INF
NINF
N HexDigits P Exponent
HexDigits P Exponent
Exponent:
N Number
Number
HexDigits:
HexDigit
HexDigit HexDigits
HexDigit:
Digit
A
B
C
D
E
F
- n
- is for null arguments.
- Number
- is for positive numeric literals (including character literals).
- N Number
- is for negative numeric literals.
- e HexFloat
- is for real and imaginary floating point literals.
- c HexFloat c HexFloat
- is for complex floating point literals.
- Width Number _ HexDigits
- Width is whether the characters are 1 byte (a), 2 bytes (w) or 4 bytes (d) in size. Number is the number of characters in the string. The HexDigits are the hex data for the string.
- A Number Value...
- An array literal. Value is repeated Number times.
Name:
Namestart
Namestart Namechars
Namestart:
_
Alpha
Namechar:
Namestart
Digit
Namechars:
Namechar
Namechar Namechars
A Name is a standard D identifier.
LName:
Number Name
Number:
Digit
Digit Number
Digit:
0
1
2
3
4
5
6
7
8
9
An LName is a name preceded by a Number giving the number of characters in the Name.
Type Mangling
Types are mangled using a simple linear scheme:
Type:
Shared
Const
Immutable
TypeArray
TypeNewArray
TypeStaticArray
TypeAssocArray
TypePointer
TypeFunction
TypeIdent
TypeClass
TypeStruct
TypeEnum
TypeTypedef
TypeDelegate
TypeNone
TypeVoid
TypeByte
TypeUbyte
TypeShort
TypeUshort
TypeInt
TypeUint
TypeLong
TypeUlong
TypeFloat
TypeDouble
TypeReal
TypeIfloat
TypeIdouble
TypeIreal
TypeCfloat
TypeCdouble
TypeCreal
TypeBool
TypeChar
TypeWchar
TypeDchar
TypeTuple
Shared:
O Type
Const:
x Type
Immutable:
y Type
TypeArray:
A Type
TypeNewArray:
Ne Type
TypeStaticArray:
G Number Type
TypeAssocArray:
H Type Type
TypePointer:
P Type
TypeFunction:
CallConvention FuncAttrs Arguments ArgClose Type
CallConvention:
F // D
U // C
W // Windows
V // Pascal
R // C++
FuncAttrs:
FuncAttr
FuncAttr FuncAttrs
FuncAttr:
empty
FuncAttrPure
FuncAttrNothrow
FuncAttrProperty
FuncAttrRef
FuncAttrTrusted
FuncAttrSafe
FuncAttrPure:
Na
FuncAttrNothrow:
Nb
FuncAttrRef:
Nc
FuncAttrProperty:
Nd
FuncAttrTrusted:
Ne
FuncAttrSafe:
Nf
Arguments:
Argument
Argument Arguments
Argument:
Argument2
M Argument2 // scope
Argument2:
Type
J Type // out
K Type // ref
L Type // lazy
ArgClose
X // variadic T t,...) style
Y // variadic T t...) style
Z // not variadic
TypeIdent:
I LName
TypeClass:
C LName
TypeStruct:
S LName
TypeEnum:
E LName
TypeTypedef:
T LName
TypeDelegate:
D TypeFunction
TypeNone:
n
TypeVoid:
v
TypeByte:
g
TypeUbyte:
h
TypeShort:
s
TypeUshort:
t
TypeInt:
i
TypeUint:
k
TypeLong:
l
TypeUlong:
m
TypeFloat:
f
TypeDouble:
d
TypeReal:
e
TypeIfloat:
o
TypeIdouble:
p
TypeIreal:
j
TypeCfloat:
q
TypeCdouble:
r
TypeCreal:
c
TypeBool:
b
TypeChar:
a
TypeWchar:
u
TypeDchar:
w
TypeTuple:
B Number Arguments

Wiki
Search
Downloads
Home