News for hackers. Stuff that matters.
Re:Self hosted C – breakdown by hbbio on Friday December 04, 2015 @05:50AM (#10675606)
Thanks for providing the links that compare your for loop parser to existing implementations, it's interesting:

- Gcc is unreadable;

- Clang is "advanced", but not readable;

- yours and tcc are clean... But you know it's always a risk to compare yourself to Fabrice Bellard :)

Re:Self hosted C – breakdown by david-given on Friday December 04, 2015 @07:03AM (#10675828)
Just to continue the catalogue:

pcc is simple, but very old school and a bit contorted.

libfirm is small and clean and generates excellent code. (Despite the name, it's a complete ANSI C compiler, as well as being a LLVM-light.)

The ACK is easy to port and is a complete standalone toolchain including compilers, assemblers and linkers, but (at least on modern processors) produces code so bad that it will make you want to stab yourself in the eyes to make the pain go away.

There's a look-but-don't-touch licensed compiler called vbcc which is by far the best C compiler I've ever seen; small, easy to understand, easy to port, and produces excellent code... but the author doesn't want to release it under an open source license.

Any others?

Re:Self hosted C – breakdown by david-given on Friday December 04, 2015 @12:18PM (#10677570)
Oh, here's a couple more I forgot about:

nwcc: small, slightly unfinished, looks like it's stalled.

sparse: technically this isn't a compiler, it's a code linter --- but it contains a complete ANSI C front end and a reasonable amount of a backend and can be made to generate code without much effort. I've used it to compile C to Java and Perl. There's no optimisation layer and it's a little buggy (it's not really really intended as a compiler).

Re:Self hosted C – breakdown by andrewchambers on Friday December 04, 2015 @07:12AM (#10675857)
libfirm doesn't really classify as small to me, it is currently 132,638 lines of code. The cparser alone is 11k lines of code (5 times the size of my c parser).
Re:Self hosted C – breakdown by david-given on Friday December 04, 2015 @09:14AM (#10676388)
That's true. I was rather thinking of it in comparison to LLVM and gcc, which are both space-distorting behemoths. (The catchphrase I've seen is that you can compile libfirm in less time than it takes to run the gcc configure script!)
Re:Self hosted C – breakdown by nwmcsween on Friday December 04, 2015 @01:31PM (#10678097)
Does your cparser cover the entire c spec?
Re:Self hosted C – breakdown by andrewchambers on Friday December 04, 2015 @03:55PM (#10679075)
Not currently, but it covers probably more than 80 percent. Part of the problem is support gcc extensions which take some more work.
Re:Self hosted C – breakdown by userbinator on Friday December 04, 2015 @09:09PM (#10680486)
The GCC extensions are just that - they're not part of the standard. You can claim 100% standards conformance without implementing a single one of them.

That said, in practice a large amount of C code out there is not pure standard C so if you want to be able to compile something "interesting" like e.g. a Linux kernel you'll need to implement some.

Re:Self hosted C – breakdown by tomp on Friday December 04, 2015 @07:26AM (#10675913)
> Node n, i, c, s, *st;

I disagree; "brevity" and "readability" are unfortunately a tradeoff, and IMO the author's version optimizing the wrong metric.

Re:Self hosted C – breakdown by andrewchambers on Friday December 04, 2015 @04:03PM (#10679109)
I think you will notice that each of those variables is assigned to the true name within a few lines of the declaration.

n->For.init = i; n->For.step = st; ...

This is why it is clear. Though I could change it to be better.

Re:Self hosted C – breakdown by andrewchambers on Friday December 04, 2015 @05:53AM (#10675614)
Tcc is far faster. I have done some benchmarks and tcc is really incredible. He was just optimising for a different goal I think.

edit:

Compiling my parse.c file, tcc is 34 times faster than gcc -O0 and my compiler is 3-4 times faster than gcc -O0. I should make a post with the actual stats.

Re:Self hosted C – breakdown by david-given on Friday December 04, 2015 @09:20AM (#10676420)
It's worth mentioning that tcc started life as an entry in the Obfuscated C Contest:

http://bellard.org/otcc/

(It won.)

Re:Self hosted C – breakdown by ksherlock on Friday December 04, 2015 @08:48AM (#10676251)
LCC's for statement is also clean and understandable.

https://github.com/drh/lcc/blob/master/src/stmt.c#L263