
CC500: a tiny self-hosting C compiler - userbinator
http://homepage.ntlworld.com/edmund.grimley-evans/cc500/
======
progman
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.

~~~
beagle3
This was here just 3 days ago:
[https://news.ycombinator.com/item?id=8558822](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?

~~~
progman
> 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.

~~~
qznc
Do you know the "portable c compiler" PCC?

[http://pcc.ludd.ltu.se/](http://pcc.ludd.ltu.se/)

~~~
progman
Thanks! I will study it.

------
logicallee
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.

------
jaytaylor
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](http://www.bellard.org/otcc/otcc.c)

~~~
huegh
I propose the tinyness of a compiler is directly proportional to the number of
comments spontaneously arguing it isn't.

~~~
EGreg
That means it can be gamed

------
codingcoding
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?

------
Zardoz84
And now, to check how port it to TR3200 cpu...

------
jokoon
what does he mean by "self-hosting" ? I mean it generates a binary.

~~~
mungoman2
It means it can compile itself.

~~~
jenscow
And the significance being, this compiler can handle code complex enough to
create a compiler.

~~~
vidarh
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.

