Aro: A C compiler written in Zig
github.com
github.com
I see WalterBright down there in the comments. Hi! His talk at Handmade Seattle about adding a C compiler to D was amusing and informative: https://media.handmade-seattle.com/importc/
Some interesting differences between the two approaches:
* D ImportC relies on an external preprocessor, while Aro does preprocessing.
* D ImportC lowers to D AST, while Aro lowers Zig AIR. This tweet has an infographic to help you get an idea of where AIR is in the Zig compiler pipeline: https://twitter.com/andy_kelley/status/1457800302946492418
* D ImportC is shipped, while Aro as a C frontend in Zig is an [unfinished branch](https://github.com/ziglang/zig/pull/10795)
It's been really exciting watching Vexu and ehaas (and other contributors) working on Aro.
Looks like there's some confusion as to why this exists when Zig already uses libclang to compile C code. The main reasons are:
* Improved `@cImport`/translate-c functionality, especially with regards to translation of macros. Vexu and ehaas are the main contributors of Zig's C translation implementation.
* Ability to bootstrap a lean Zig binary that does not depend on LLVM, and yet is still able to compile C code and use the `@cImport` language feature to translate C code.
* Ability to more tightly integrate with Zig's linker, bringing some incremental compilation abilities to C. Due to language limitations it can never be as good as Zig but it can still be improved over other C compilers.
* Ability to compile C code to targets that LLVM does not support. Zig plans to support a wider target range than LLVM.
2 questions:
- What are some books or resources you would recommend to get into (practical) low level programming with the goal of writing better Zig code? I know my basic self defense in C, and from a gut feeling I'd say C resources carry over the most but I'd be interested in how you see things and which resources you like or see a decent carryover in.
- I personally enjoy reading the Zig source code to learn the language. But what is something you'd like to see arise to improve the teaching of Zig in the future and once things get closer to 1.0?
I have been reading Richard Fabian's book, Data-Oriented Design, and finally things started to "click" for me. I've had these ideas swirling around in my head for years, but only recently do I feel like I have an intuitive grasp on how modern CPUs work, especially with regards to L1 cache, and the relative latencies of uncached memory loads vs computations.
[1] https://ziglang.org/download/0.8.0/release-notes.html#Rework...
LLVM is being placed as a an optional component in the future [2]. Using arocc to fill this gap would mean that seamless C compilation could still be done, without LLVM being involved.
Wouldn't it be way more beneficial to extend LLVM instead?
If it was trivial I can assure you the Rust folk would have already been at it.
2021 LLVM Developers Meeting “Enabling Interactive C++ with Clang”
https://www.youtube.com/watch?v=33ncbIQoa4c
Currently the best developer experience for hot code reload for C++ is Visual C++ 2022.
If you're interested, they have monthly meetups open to the public, with fantastic speakers and presentations:
A bit 'out there' you may say, but on the plus side this approach enables handling header files and tidily expressing bindings without the need to implement their own C parser. [2]
[0] GitHub mirror: https://github.com/forthy42/gforth/blob/dda77d851ddeb80ca849...
[1] The official host: https://git.savannah.gnu.org/cgit/gforth.git/tree/libcc.fs
[2] https://rosettacode.org/wiki/Call_a_foreign-language_functio...