4 ms·
Please identify a system where you might want to run a compiler, and there is no C++ compiler for it. There are of course many places you might run code that c
by moloch-hai 4y ago
Please identify a system where you might want to run a compiler, and there is no C++ compiler for it.
There are of course many places you might run code that cannot host a compiler for any language. You use a cross compiler for those.
- satvikpendem 4y agoAre there not a lot of embedded systems that only have a C compiler?
- moloch-hai 4y agoYou want to run a Zig compiler on an embedded system?
- satvikpendem 4y agoNot sure I understand your question, why wouldn't someone want to use Zig (or Rust, or Nim) instead of C or C++?
- moloch-hai 4y agoThis is about the language the compiler itself is coded in. It would be absurd to try to run a compiler on your ESP microcontroller just because that is where the program you are compiling is supposed to run. (That does not stop Forth fans, of course.) People do often run compilers on RaspPis and the like (though rarely for any good reason), but those compilers are most often coded in C++, whatever the language it is compiling, just like Zig's original compiler. Most of the Rust compiler is in C++, and they have no plan to change that.
- TUSF 4y ago> Most of the Rust compiler is in C++, and they have no plan to change that. What? I just went and searched the Rust compiler, and the only C++ code to speak of was LLVM itself, and a thin wrapper around LLVM to provide a C API. Which is pretty much the same state that Zig is in right now. (Although in Zig's case, LLVM is optional) Yeah, it's a lot of C++ that the Rust compiler relies on, but I don't think most people would really compare things like that.
- steveklabnik 4y ago… and the cranelift backend is in Rust, so “no plans to change that” is half correct at best.
- int_19h 4y agoRasPis and the like are literally more powerful than your typical desktop PC 20 years ago. They can run all kinds of compilers, interpreters etc just fine, including those that are bootstrapped. Real embedded is more challenging, but even then... DOS ran on 640 Kb of RAM for userspace, and it had C and even C++ (albeit pre-ISO) compilers, and many embedded platforms these days come with something comparable. Forth is really only necessary if you want to bootstrap on really low-memory stuff. "Why" is a different question. ~
- josephg 4y agoThe fact that basically every platform has a working C compiler is why this approach works. The benefit of this compared to the previous approach is that the developers no longer need to maintain a second compiler written in C++.
- moloch-hai 4y agoThey have only ever needed to maintain the one, original compiler. The one in Zig is the second one, and is not strictly needed at all. There was a time when self-hosting your language made sense. I did notice that you did not identify the system which can run a C compiler but cannot run a C++ compiler.
- mwcampbell 4y ago> There was a time when self-hosting your language made sense. Why doesn't it now?
- moloch-hai 4y agoBecause it is an absurd waste of time. Once, good compilers were rare and expensive, and coding a compiler in your new language proved to people that it was adequate to implement a compiler. Nowadays good compilers for everything are common and free. Coding a compiler for your language in your language demonstrates only that you could afford to waste the time, because literally every language suffices to code a compiler in.
- josephg 4y ago> Coding a compiler for your language in your language demonstrates only that you could afford to waste the time You seem to be presupposing this is true, but this is a pretty controversial claim. Do you have any justification for it? As other people in this thread have mentioned, there are other benefits to programming your compiler using your own programming language: - You learn your language (and its rough edges) first hand - You can try out & experiment with new language features - The authors of Zig clearly think zig is better to use than C++. (If not, why would they bother inventing zig?). It makes sense that if you think Zig is a better language than C++, you'd want to write your compiler in Zig and not C++. Lots of compiler authors (you know, the people who get a vote) disagree with you on this: Clang, VC++, etc are written in C++. Rustc is written in rust. The main zig compiler is written in zig. DMD is written in D. And so on. And anyway, whats so great about C++ that it would make a good language to write compilers in in the first place? Why shouldn't I write my compiler in plain C, or Rust, or Zig, or Go, or whatever strikes my fancy?