Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: WIP C compiler in Go, inspired by 8cc (github.com/andrewchambers)
60 points by andrewchambers on March 17, 2015 | hide | past | favorite | 12 comments



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.


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


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


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().


And WIP just means "work in progress."


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.


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.


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


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


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


How does this compare to vbcc and pcc?


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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: