\

Writing a C Compiler, in Zig

37 points - today at 9:20 AM

Source
  • fuhsnn

    today at 11:25 AM

    Looking at the repo, the author seemed a little fed up [1] with the nature of lower level language and quitted.

    [1] https://github.com/asibahi/paella/blob/main/writeup/c19.md#u...

      • dwroberts

        today at 11:48 AM

        Feels like maybe something lost in translation with their explanation - they say they were fed up of data structures etc. but they returned to Rust? I’m assuming there’s something a bit more nuanced about what they got tired of with Zig

    • scatbot

      today at 11:18 AM

      Cool project. Feels like writing a C compiler in Zig aligns nicely with the old "maintain it in Zig" idea that was part of Zig's early value proposition. Is that still considered a relevant goal today?

      Longer term it also makes me wonder whether something like this could eventually reduce reliance on Clang/LLVM for the C frontend in zig's toolchain.

        • spiffyk

          today at 12:03 PM

          There is actually another C compiler written in Zig, Aro[1], which Zig started using since 0.16 for its TranslateC module.

          [1]: https://github.com/Vexu/arocc

      • flossly

        today at 11:33 AM

        I thought Zig has a C compiler built in? Or is it just the Zig build system that's able to compile C, but uses an external compiler for that?

        Still a proper programmer-flex to build another one.

          • spiffyk

            today at 12:01 PM

            Zig actually bundles LLVM's Clang, which it uses to compile C with the `zig cc` command. But the long term goal seems to not be so tightly coupled to LLVM, so I'm expecting that to move elsewhere. They still do some clever stuff around compiler-rt, allowing it to be better at cross-compilation than raw Clang, but the bulk of it is mostly just Clang.

            There is also another C compiler written in Zig, Aro[1], which seems to be much more complete than TFA. Zig started using that as a library for its TranslateC functionality (for translating C headers into Zig, not whole programs) in 0.16.

            [1]: https://github.com/Vexu/arocc