Eigenstate: myrddin-dev mailing list

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

Re: Myrddin: Partial C ABI compatibility



On August 21, 2015 10:02:01 PM CDT, Ori Bernstein <ori@xxxxxxxxxxxxxx> wrote:
>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.
>

Here be dragons. No one on earth can ever agree on how to build C code. Add in messes like configuration, and it's quite a bit of trouble.

I would personally just NOT support building C files, or have very limited support (no external pkg-config calls and such) and make people run some configure script first (not autoconf, hence my signature :).

>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

-- 
Sent from my Nexus 5 with K-9 Mail. Please excuse my brevity.

References:
Myrddin: Partial C ABI compatibilityOri Bernstein <ori@xxxxxxxxxxxxxx>