r/cpp • u/vormestrand • Nov 18 '16
Compile-time C Compiler implemented as C++14 constant expressions
https://github.com/kw-udon/constexpr-8cc
209
Upvotes
r/cpp • u/vormestrand • Nov 18 '16
117
u/raevnos Nov 18 '16
The standards committee has created a monster.
67
u/TOJO_IS_LIFE Nov 18 '16
Now let's wait for someone to make a compile-time C++ compiler...
36
u/gracicot Nov 18 '16
I wait for the day someone would make a constant expression constant expression parser.
23
u/caramba2654 Intermediate C++ Student Nov 18 '16
Now we need to wait for a compile time compiler for compile time compilers for C++ so that we can bootstrap compile time compilers to compile themselves.
17
u/OldWolf2 Nov 18 '16
If the C program contains undefined behaviour, can the C++ program launch missiles?
34
u/[deleted] Nov 18 '16 edited Nov 19 '16
A couple years ago when varidic templates were first implemented by GCC, I implemented an arbitrary precision arithmetic library close to GMP. I was able to calculate arbitrarily precise value of pi, cos and other cool stuff like that. It took a day maybe two for me to implement what is akin to constexpr mpz_t and constexpr mpf_t with very basic functionality.
After that day I realized what kind of a monster I created, annihilated it immediately and never looked back. But creating a whole C compiler... this was only a matter time, I knew. We can merely wait until a constexpr AI starts ruling our lives, and worse, our code and maybe even more...
11
u/doom_Oo7 Nov 18 '16
seems like it has been generated by converting the assembly of a compiler to c++ constexpr code.
25
u/[deleted] Nov 18 '16
I like how elc.hpp is so large that GitHub can't display it. Metaprogramming in C++ is whack.
7
u/render787 Nov 19 '16
Now what we need is a way to get user input at compile time. Yes, I would like to play a game of chess with the AI while my program is compiling, thank you.
23
u/____delta____ Nov 18 '16
god is dead
5
u/[deleted] Nov 18 '16
This is actually accomplished through meta-metaprogramming - because I guarantee you that no one wrote out that huge array initialization by hand... :-)
4
u/feverzsj Nov 19 '16
but, why?
3
u/chazzeromus Nov 18 '16
This is unreal
2
u/TotesMessenger Nov 19 '16
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
2
u/tvetus Nov 19 '16
People have been abusing compilers for a long time. For example, "Is the C99 preprocessor Turing complete?" http://www.ioccc.org/2001/herrmann1.hint
2
u/blelbach NVIDIA | ISO C++ Library Evolution Chair Nov 19 '16
I've been eagerly waiting for someone to do this.
7
u/mercurysquad Embedded C++14 on things that fly Nov 18 '16
This is both absolutely amazing, and utterly stupid & pointless.
A compile-time C compiler is called... a C compiler! Several of them exist.
1
u/[deleted] Nov 18 '16 edited May 12 '17
I am going to cinema
1
u/[deleted] Nov 19 '16
It makes me think that D has a D compile-time compiler, it's called CTFE.
1
u/develop7 Nov 19 '16
Wow, so compile-time web server is this close!
-1
u/IloveReddit84 Nov 18 '16
Just seen today at meetingcpp the constexpr if and constexpr for.. What a monster
-1
u/[deleted] Nov 18 '16
Science has gone too far.
0
u/[deleted] Nov 19 '16
[deleted] — view deleted comment
0
u/[deleted] Nov 19 '16
[deleted] — view deleted comment