1. 10
  1.  

  2. 5

    If you want something like this for your own language, it may be worthwhile to check out my cffi-gen. It generates json files from C headers.

    Also I got a C-parser implemented in Lever. I dunno if anyone would use it, especially when I’m ripe to stop it’s development and I didn’t get to finish it properly, but it may help if you are planning to do something like this yourself. c.lc cffigen.lc. This project ultimately suffered from a kind of inverse-second-system syndrome. I still ended up using the original, cffi-gen to generate most of the stuff because it still works.

    1. 2

      It generates json files from C headers.

      That’s a great idea! Makes it more reusable across projects.

    2. 4

      In CHICKEN we have had something like this for many years, in the bind egg (formerly called easyffi). I don’t really like it, to be honest. It can be very helpful for quick and dirty testing code, but a hand-written wrapper will usually result in a much better quality, more idiomatic and more high level library.

      With hand-written wrappers you would tend to drop all the C-isms like pass by reference via pointer, explicitly passing string lengths and so on. Of course you can still use bind and wrap the resulting Scheme stubs in more idiomatic code like you would in a hand-written version. But then it doesn’t offer all that much, except more overhead.

      It helps that the FFI in CHICKEN is very good, so writing C bindings manually isn’t that big a deal, in my experience.

      1. 4

        Yes. I don’t think this removes the need for writing translation code by hand, but it does remove the need to do write it entirely without the benefit of type checking – now, the compiler will complain if you accidentally forget a parameter, because you have an extern function.

        In Myrddin, there’s no FFI – there’s just ‘extern’ prototypes and a compatible ABI.

      2. 3

        myrddin is such a fun language, I encourage everyone to give it a try.

        1. 1

          have you written anything major in it? I like the fact that it supports most of the platforms I use, but I haven’t seen much written in it…

          1. 2

            I wrote the C compiler mentioned in that post and a few command line utilities like https://github.com/andrewchambers/ddmin . The compiler code was probably the biggest thing I wrote.

            1. 1

              oh that’s beautiful, thank you! Are there any pain points you’ve experienced with using it?

              1. 3

                Not much pain really, just a small project so you can’t expect too many libraries and be patient with the docs and help fix them if you can.

        2. 2

          First thing that came to my mind was Bindy McBindface.

          C must be the programming language with the most compilers in existence. I’ve already seen about a dozen or more independent implementations.

          1. 1

            Its also one of the only language I trust to still work 10 years from now because there are so many implementations