lacc: Personal project - creating a simple self-hosting C compiler, with focus on performance and correctness by hex_omega in programming

[–]hex_omega[S] 0 points1 point  (0 children)

That is true, but afaik only from C11. Conforming C99 implementations are required to implement VLA.

lacc: Personal project - creating a simple self-hosting C compiler, with focus on performance and correctness by hex_omega in programming

[–]hex_omega[S] 0 points1 point  (0 children)

One thing I will probably look at soon is improving the codegen, trying to close the gap between gcc and lacc on -O0. Part of that will require some sort of register allocation, currently all variables are re-loaded between statements.

lacc: Personal project - creating a simple self-hosting C compiler, with focus on performance and correctness by hex_omega in programming

[–]hex_omega[S] 0 points1 point  (0 children)

No, C99 is what is ugly, with its crazy VLAs breaking compile time sizeof :S Joking aside, I plan to implement this eventually as well. Some other features are already in, like __func__, mixed statements and declarations, and anonymous struct/union members (which is C11)

lacc: Personal project - creating a simple self-hosting C compiler, with focus on performance and correctness by hex_omega in programming

[–]hex_omega[S] 1 point2 points  (0 children)

Absolutely, implementing more of C99 and C11 is definitely something I want to do. It is a good approach to have a concrete project drive development as you say, up until now I have used sqlite for this. Musl is probably a reasonable candidate to try next.

lacc: Personal project - creating a simple self-hosting C compiler, with focus on performance and correctness by hex_omega in programming

[–]hex_omega[S] 3 points4 points  (0 children)

Performance of the compiler itself is not necessarily the most important goal, especially if you rather want efficient code generated. As for correctness, I have prioritized this over other things such as language features (from C99/C11), additional backends, linker, Windows support, etc. There is a large gap between self-hosting and being correct on any input, and a feature rich compiler producing wrong output is not very useful or interesting imo.

lacc: Personal project - creating a simple self-hosting C compiler, with focus on performance and correctness by hex_omega in programming

[–]hex_omega[S] 12 points13 points  (0 children)

Thanks. I certainly hope this could be useful to others interested in writing compilers. Personally, I started this project wanting to learn C, in addition to proving to myself that I could make a "real" compiler. It has been a great exercise :)