

Show HN: WIP C compiler in Go, inspired by 8cc - andrewchambers
https://github.com/andrewchambers/cc

======
rikkus
The code is very easy to read, so I think this would be great for those who
want to learn how one might go about implementing a C compiler.

~~~
andrewchambers
I personally struggled to work with other compilers, I think TCC is too terse,
and GCC/Clang have too much code.

[https://github.com/rui314/8cc](https://github.com/rui314/8cc) Got things
right, and I am trying continue with it's style.

I will be happy if a student can take my compiler and port it to his own
invented cpu with a modest amount of work.

~~~
userbinator
Terseness is quite a subjective thing, as I think TCC is not all that small
among all the C (and C-subset) compilers that exist like Small-C; on the other
hand, _OTCC_ is in realm of "too terse" for me.

This one is more agreeable with my style (and I think the parser in it is
amazingly concise and elegant):

[https://github.com/rswier/c4/blob/master/c4.c](https://github.com/rswier/c4/blob/master/c4.c)

~~~
andrewchambers
TCC packs a C compiler, assembler and linker together, So it has a large
amount of functionality, even if it is no longer so tiny. The code style is
really dense too. Frequently using single letter function and variable names.

e.g. Outputting data into the final data segments uses functions named o() and
o32().

------
acqq
And WIP just means "work in progress."

~~~
andrewchambers
Yeah, there is still a lot to do. I posted because sometimes showing others
helps keep yourself motivated.

I'd love to find collaborators too, though I don't expect anyone to help until
less trivial programs are running.

~~~
acqq
At first I thought "WIP C" meant something related to the kind of C or of the
C compiler, that's why I commented. If you can still change the title, writing
"work-in-progress" instead of WIP would be much less confusing.

And good luck in your efforts, you've set some really serious goals.

~~~
andrewchambers
Thanks, Its a marathon type of project, not a sprint.

------
userbinator
The reason why this isn't a Go compiler in Go is probably the same reason why
it's a C compiler - the complexity of the language. C seems to be the sweet
spot for a language that is relatively easy to write a basic compiler for, but
also powerful enough to be used for writing nontrivial software (including
compilers.)

~~~
andrewchambers
Its not too bad to write a Go compiler in Go, simply because of this package
[https://godoc.org/golang.org/x/tools/go/ssa](https://godoc.org/golang.org/x/tools/go/ssa)
by the Go team.

I really hope someone writes a Go to C compiler in Go, as combined with my C
compiler, they would create an entirely new and self hosting implementation of
Go.

------
iso8859-1
How does this compare to vbcc and pcc?

~~~
andrewchambers
This still as a long way to go before it could be compared to them in terms of
completeness,

