merge-2.069 now builds (and passes most of) the test suite
Jacob Carlborg via digitalmars-d-ldc
digitalmars-d-ldc at puremagic.com
Fri Feb 19 02:57:53 PST 2016
On 2016-02-19 02:04, Dan Olson wrote:
> I might be able to help once I get done with arm-linux.
Ok, cool.
> Last summer for fun I started integrating your older fully functional obj-d branch with
> ldc. I got instance method calls and selectors working, although the
> code was very much a kludge.
It's only external classes and instance methods that are implemented so
far in upstream DMD.
The commit message for the commit [1] that implements the support
contains some explanation on how it works. The explanation is pretty
high level and doesn't explain the data layout in the object files.
I included the commit message here for convince:
================ Commit Message ================
Basic support for classes, interfaces and instance methods.
This is implemented by adding a new linkage attribute, `Objective-C`,
and a compiler recognized UDA, `@selector`. The linkage attribute is
to be used on a class or interface. The UDA is attached to a method.
The linkage attribute tells the compiler that the class should use the
name mangling that matches the one used by Objective-C
(same as C, no mangling) and that all methods in the class
should use the Objective-C way of calling methods, see below.
The calling convention for Objective-C methods and functions is the
same as for C.
The selector UDA tells the compiler what Objective-C selector the
method should have. The selector is used in the Objective-C runtime
to find the implementation of a given method.
An Objective-C method call is implemented by making a regular C call
to the `objc_msgSend` function in the Objective-C runtime.
The signature of `objc_msgSend` looks something like this:
`id objc_msgSend(id self, SEL op, ...);`
* The first parameter is the object (this/self pointer)
* The second parameter is the selector attached to the method
* The last parameter is for all the arguments that the
implementation expects
The call to `objc_msgSend` should not be performed as a variadic
call but instead as if it had the same signature as the method
that should be called but with the two additional parameter,
`self` and `op`, added first. The implementation of `objc_msgSend`
will jump to the method instead of calling it.
Because of the above, multiple versions exist of `objc_msgSend`.
Depending on the return type of the method that is called the correct
version need to be used. This depends on the ABI. This is a list of
functions and for which types they're used on OS X 64bit:
* objc_msgSend_stret - Used for structs too large to be returned in
registries
* objc_msgSend_fpret - Used for `long double`
* objc_msgSend_fp2ret - Used for `_Complex long double`
* objc_msgSend - Used for everything else
[1] 867d5479b6d98b23b6c797ee487d1ec1474bee10
--
/Jacob Carlborg
More information about the digitalmars-d-ldc
mailing list