Live data from Hacker News

Oops, I Wrote a C++ Compiler

praeclarum.org

21–30 of 42 posts

Re: Oops, I Wrote a C++ Compiler

#21

Earlier quoted context omitted.

> Why not use GCC or LLVM as part of your project? That's not how the world gets compiler people. Someone had to write GCC and LLVM, and someone will have to write whatever comes next. Languages and tooling only advance because there are those who choose to take the hard road instead of "just using that thing that someone else made".

The successor to LLVM isn't going to be written by someone just hacking on an app and decides they could use a basic compiler. It's going to be written by someone who has the explicit goal of replacing LLVM, fully understands LLVM's design and tradeoffs, and has ideas about an architecture for a successor that improves on the design. Encouraging people to use LLVM instead of home-growing a toy compiler can still get…

> It's going to be written by someone who has the explicit goal of replacing LLVM, fully understands LLVM's design and tradeoffs, and has ideas about an architecture for a successor that improves on the design.

And from where would they get those ideas? Tweaking LLVM is not enough to learn the necessary trade-offs. You need to write a compiler from the ground up. In fact you need to do it multiple times. Most likely you will not end up writing a LLVM replacement. Most likely you will end up a better programmer.

Re: Oops, I Wrote a C++ Compiler

#22
post #3

Please don't call it C++ if it doesn't even support constructors and destructors. People will be trying to port their existing code, and will be unpleasantly surprised. > But the truth is, I’m just going to keep listening to users and improving the parts I can. I am not trying to recreate GCC or LLVM. Why not use GCC or LLVM as part of your project? That seems like a better investment of your time.

Am I seeing things or there's a recent trend of claiming things are C++ compilers when they're nowhere near that?

Just yesterday there was this, which doesn't even support structs:

https://news.ycombinator.com/item?id=17843293

I'm all for simple instructive projects, but we don't need to describe them in such misleading ways.

Re: Oops, I Wrote a C++ Compiler

#24
post #3

Please don't call it C++ if it doesn't even support constructors and destructors. People will be trying to port their existing code, and will be unpleasantly surprised. > But the truth is, I’m just going to keep listening to users and improving the parts I can. I am not trying to recreate GCC or LLVM. Why not use GCC or LLVM as part of your project? That seems like a better investment of your time.

The destructors happen to be one of the most important features that distinguishes C++ from C imho (automatic cleanup at end of scope), so would be great to implement those!

Re: Oops, I Wrote a C++ Compiler

#26
post #3

Please don't call it C++ if it doesn't even support constructors and destructors. People will be trying to port their existing code, and will be unpleasantly surprised. > But the truth is, I’m just going to keep listening to users and improving the parts I can. I am not trying to recreate GCC or LLVM. Why not use GCC or LLVM as part of your project? That seems like a better investment of your time.

Integrating LLVM requires quite a lot of mental effort (Let's not even discuss GCC...), whereas writing from scratch can be "simpler" mentally (at least to start with).

Re: Oops, I Wrote a C++ Compiler

#27

More like a “C++ [1] compiler”. [1] restrictions may apply

To be honest, that's most C++ compilers.

That's only technically true. The main C++ compilers in common use basically support, aim to support or have collectively agreed not to support parts of the C++ standard.

Re: Oops, I Wrote a C++ Compiler

#28
post #14

Nice! I think doing this is a great learning experience. I think I understand how to write a basic compiler but I am completely stumped by writing an optimizer. How do you model that?

It's a bit idiosyncratic but Steven Muchnick's "Advanced Compiler Design and implementation" is something of a bible for optimising compiler design. Of course, other books are available.

I haven't look around recently enough to name any off-hand but there are some really good free textbooks/monographs(etc.) on optimisation around. Search "ssabook", there's a really great data flow analysis book out there somewhere which if I find I will edit and include.

Re: Oops, I Wrote a C++ Compiler

#29

Earlier quoted context omitted.

> Please don't call it C++ if it doesn't even support constructors and destructors. At least they recognize this is missing, and call it out. > Why not use GCC or LLVM as part of your project? That seems like a better investment of your time. Learning opportunity? Maybe they're trying to solve a problem? Or do you think the LLVM folks should have just used GCC instead of wasting their time on LLVM?

Aren't constructors and destructors basically the main idea of c++?

C++ is too big to have any "main feature", but in any case yeah, it's a huge deal.

Re: Oops, I Wrote a C++ Compiler

#30
post #6
post #3

Please don't call it C++ if it doesn't even support constructors and destructors. People will be trying to port their existing code, and will be unpleasantly surprised. > But the truth is, I’m just going to keep listening to users and improving the parts I can. I am not trying to recreate GCC or LLVM. Why not use GCC or LLVM as part of your project? That seems like a better investment of your time.

It is very well explained? GCC and Clang would be nightmares to integrate into an app that runs on many platforms including iOS, and even once you did, you'd still need to implement an interpreter, because you're not allowed to JIT on the app store. Compiling a toolchain for a desktop platform is easy. Cross compiling a toolchain is moderately easy. But embedding a toolchain into an iOS app, where you have to get it…

[deleted]
Post reply on HN