Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Myrddin: Partial C ABI compatibility


C ABI compatibility on Linux is partly done. Floats, ints, pointers, and
anything else in that class of types is likely to work.

Passing structs or unions will not work, although passing pointers to them
should be ok. Doing anything interesting in C will involve adding a call to
initialize libc.

Making this work on Plan 9 shouldn't be too far off, and I believe that it
will be easier to make it 100% ABI compatible.

Integrating it into the build system is another task, and I'm not sure how
that would be best done at the moment.

Example:

=== Myrddin ===

    use std

    type s = struct
            a : int
            b : int
            c : byte[:]
    ;;

    extern const frob : (a : int, b : int, c : uint64, d : s#, str : byte[:]# -> int)
    const main = {
            var s = [.a = 1000, .b = 2000, .c = "abc"]
            var str = "abcd"
            std.put("{}\n", frob(1, 2, 3, &s, &str))
    }

=== C ===

    #include <stdlib.h>
    #include <stdint.h>

    typedef struct Myrsl Myrsl;
    typedef struct S S;

    struct Myrsl {
            void *p;
            size_t len;
    };

    struct S {
            int a;
            int b;
            Myrsl c;
    };

    int
    frob(int a, int b, uint64_t c, S *d, Myrsl *str)
    {
            return a + b + c + d->a + d->b + d->c.len + str->len;
    }

=== To compile ===

    6m myrcode.myr
    cc -c ccode.c
    ld -o mixed $prefix/lib/myr/_myrrt.o myrcode.o ccode.o -L$prefix/lib/myr -lstd -lsys 
    $ ./mixed
    3013

-- 
    Ori Bernstein

Follow-Ups:
Re: Myrddin: Partial C ABI compatibilityRyan Gonzalez <rymg19@xxxxxxxxx>