merge-2.069 now builds (and passes most of) the test suite

Dan Olson via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Sat Feb 20 13:29:51 PST 2016


Jacob Carlborg <doob at me.com> writes:

> On 2016-02-19 02:04, Dan Olson wrote:
>
> It's only external classes and instance methods that are implemented
> so far in upstream DMD.

I think I had most of that working, but I'll have to review my old work.

> 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:

It's a good description and I am excited to get it working!

I looked back and I stopped working on integrating your branch with LDC
in Aug 2015.  I think that was when I realized there were darwin ABI
problems with return structs like struct PointF {float x, y;} and worked
on that instead.

Here was my last test file, with an example of what seemed to work.
There was a companion mainm.m file that defined MyClass and called dcall().

import objc.types;

struct PointF {
    float x, y;
}

struct PointR {
    real x, y;
}

extern (Objective-C)
class MyClass : NSObject
{
    int xyzzy;
    void funAtPointF(int i, PointF p) @selector("fun:atPointF:");
    void fun(int i) @selector("fun:");
    void fun(int a,int b) @selector("fun:and:");
    void foo(); // @selector("foo");
    int ifoo() @selector("ifoo");
    float ffoo() @selector("ffoo");
    double dfoo() @selector("dfoo");
    real rfoo() @selector("rfoo");
    creal crfoo() @selector("crfoo");
    PointF pfoo() @selector("pfoo");
    PointR prfoo() @selector("prfoo");
}

extern(C) int printf(const char*, ...);

extern(C)
int dcall(MyClass c)
{
    c.fun(42);
    c.fun(10, 1);
    c.funAtPointF(42, PointF(13,99));
    c.foo();

    auto i = c.ifoo();
    printf("%d\n", i);
    auto f = c.ffoo();
    printf("%f\n", f);
    auto d = c.dfoo();
    printf("%f\n", d);
    auto r = c.rfoo();
    printf("%Lf\n", r);
    //auto cr = c.crfoo();
    auto p = c.pfoo();
    printf("%g %g\n", p.x, p.y);
    auto pr = c.prfoo();
    printf("%Lg %Lg\n", pr.x, pr.y);

    void __selector(int) funSel = &MyClass.fun;
    funSel(c, 42);

    void __selector(int,int) funAndSel = &MyClass.fun;
    funAndSel(c, 1,10);

    auto funAtPointFSel = &MyClass.funAtPointF;
    //void __selector(int,PointF) funAtPointFSel = &MyClass.funAtPointF;
    funAtPointFSel(c, 101, PointF(1.5, 3.125));

    void __selector() fooSel = &MyClass.foo;
    fooSel(c);

    int __selector() ifooSel = &MyClass.ifoo;
    return ifooSel(c);
}

Output looked like this:
$ build/bin/ldc2 classd.d -c
$ cc mainm.m classd.o build/lib/libdruntime-ldc.a -lobjc
$ ./a.out
fun(42)
fun(10,1)
fun(42, PointF(13,99))
foo()
42 <- ifoo()
42
42 <- ffoo()
42.000000
42 <- dfoo()
42.000000
42 <- rfoo()
42.000000
42,2112 <- pfoo()
42 2112
42,2112 <- prfoo()
42 2112
fun(42)
fun(1,10)
fun(101, PointF(1.5,3.125))
foo()
42 <- ifoo()
dcall returned 42

-- 
Dan



More information about the digitalmars-d-ldc mailing list