News for hackers. Stuff that matters.
Re:CC500: a tiny self-hosting C compiler by progman on Saturday November 08, 2014 @03:29AM (#8576353)
Nice hack! The next step would probably be a CC which compiles to a minimal virtual CPU instruction set so that we just need some Assembler macros to port it to a native platform (x86, ARM, etc.), plus a library of formats (ELF etc.) to create applications for those platforms.
Re:CC500: a tiny self-hosting C compiler by beagle3 on Saturday November 08, 2014 @07:11AM (#8576630)
This was here just 3 days ago: https://news.ycombinator.com/item?id=8558822 ; Now, YOU just need to write those assumbler macros. But why? Are you in some shortage of working compilers?
Re:CC500: a tiny self-hosting C compiler by progman on Saturday November 08, 2014 @07:55AM (#8576725)
> Are you in some shortage of working compilers?

I am just interested in a small maintainable C compiler which can easily be adopted to bootstrap a new platform or cpu (on FPGA). I consider such a tiny C compiler just a convenient assembler to implement basic things on new platforms.

I know GCC and Clang/LLVM but those tool chains are really big, and I guess it requires a lot of work to support a new platform and to polish all things so that everything works properly.

A portable tiny GCC/LLVM replacement for small embedded systems would be really nice. GCC and Clang are great for powerful systems but I consider them overkill for small systems.

Re:CC500: a tiny self-hosting C compiler by qznc on Saturday November 08, 2014 @08:10AM (#8576758)
Do you know the "portable c compiler" PCC?

http://pcc.ludd.ltu.se/

Re:CC500: a tiny self-hosting C compiler by progman on Saturday November 08, 2014 @08:16AM (#8576770)
Thanks! I will study it.
Re:CC500: a tiny self-hosting C compiler by beagle3 on Saturday November 08, 2014 @02:22PM (#8577866)
Fabrice Bellard's "tiny cc"[0] is a great sweet spot between "not even a portable assembler" like CC500 and C4, and GCC/LLVM:

It is a full-blown C compiler with enough extensions to compile the Linux kernel (and boot to it directly - look at the "tccboot" project). But it's also small enough and simple enough to retarget in a few days work (make that a few month if you want optimizations ... but you don't seem to).

[0] http://bellard.org/tinycc

Re:CC500: a tiny self-hosting C compiler by MatzeBraun on Saturday November 08, 2014 @11:31AM (#8577314)
Re:CC500: a tiny self-hosting C compiler by vog on Saturday November 08, 2014 @05:19AM (#8576492)
I believe this is how modern compilers work anyway. GCC as well as clang (via llvm) have multiple frontends (one for each programming language) and multiple backends (one for each target platform.)
Re:CC500: a tiny self-hosting C compiler by logicallee on Sunday November 09, 2014 @09:05AM (#8579913)
Nice project, but is it just me or is calling this a "C" compiler a bit of a stretch? Couldn't the title read CC500: a tiny self-hosting subset-of-C compiler.

I realize it looks like C, but then so does anything with the words if, while, and braces. (It doesn't seem to have the word "for".) Since it says the compiler "does not even parse the types", that part seems like window-dressing and not part of the language.

I bet you could write the complete reference for the language this compiles in a paragraph.

Re:CC500: a tiny self-hosting C compiler by jaytaylor on Saturday November 08, 2014 @02:11AM (#8576270)
Does 767 LoC / 17KB really get to be considered tiny? I mean, sure, it's small and efficient.. but there are other contenders to consider, such as Fabrice Bellard's [0] tiny obfuscated self-hosting c-compiler in under 500 lines.

How can we unambiguously distinguish between what qualifies for the classification of a "tiny" c-compiler versus just a "small" one?

[0] http://www.bellard.org/otcc/otcc.c

Re:CC500: a tiny self-hosting C compiler by boomlinde on Saturday November 08, 2014 @07:04AM (#8576623)
> How can we unambiguously distinguish between what qualifies for the classification of a "tiny" c-compiler versus just a "small" one?

We don't care about an unambiguous distinction.

Re:CC500: a tiny self-hosting C compiler by vidarh on Saturday November 08, 2014 @10:51AM (#8577188)
767 LoC of code including comments describing the grammar. Strip out the comments and you're already do to 600. Move opening brackets and a other very few steps, and you get it down to 560. Getting this below 500 lines should be fairly trivial.

So if your comparison is the completely unreadable otcc, then I'd say yes, this qualifies.

Re:CC500: a tiny self-hosting C compiler by wlievens on Saturday November 08, 2014 @02:56AM (#8576317)
If you compare it to the gargantuan that is an actual production compiler, it sure is tiny.
Re:CC500: a tiny self-hosting C compiler by userbinator on Saturday November 08, 2014 @10:55AM (#8577203)
The distinctions are quite arbitrary since there currently isn't anything like a size-competition for compilers, but if forced to make categories, I'd consider <1kLoC to be "tiny" and <10kLoC "small".

In contrast, GCC is nearing 10MLoC - 4 orders of magnitude difference - and its C parser alone is >10kLoC: https://github.com/gcc-mirror/gcc/blob/master/gcc/c/c-parser...

Re:CC500: a tiny self-hosting C compiler by huegh on Saturday November 08, 2014 @02:42AM (#8576306)
I propose the tinyness of a compiler is directly proportional to the number of comments spontaneously arguing it isn't.
Re:CC500: a tiny self-hosting C compiler by EGreg on Saturday November 08, 2014 @11:44AM (#8577379)
That means it can be gamed
Re:CC500: a tiny self-hosting C compiler by codingcoding on Saturday November 08, 2014 @02:12PM (#8577842)
I am playing with your code. But all my inputs end with error in the program function. Could you provide one meaningful example, which cc500 compiles completely?
Re:CC500: a tiny self-hosting C compiler by Zardoz84 on Saturday November 08, 2014 @04:00AM (#8576396)
And now, to check how port it to TR3200 cpu...
Re:CC500: a tiny self-hosting C compiler by jokoon on Saturday November 08, 2014 @04:10AM (#8576405)
what does he mean by "self-hosting" ? I mean it generates a binary.
Re:CC500: a tiny self-hosting C compiler by mungoman2 on Saturday November 08, 2014 @04:15AM (#8576416)
It means it can compile itself.
Re:CC500: a tiny self-hosting C compiler by jenscow on Saturday November 08, 2014 @08:56AM (#8576864)
And the significance being, this compiler can handle code complex enough to create a compiler.
Re:CC500: a tiny self-hosting C compiler by vidarh on Saturday November 08, 2014 @10:53AM (#8577198)
And it also means (thought this used to be more significant) that porting it to a new platform "just" means re-targeting the code generator and recompiling.