Reputation: 8722
I want to make a compiler for my own programming language. Popular backend choices seem to be C, Java, LLVM, JVM bytecode, .Net bytecode, gcc, assembly... Here, I am considering the possibility of Go as a backend.
Go is apparently a fast language, with garbage collection, and fast compile times. It is also portable and free (BSD-style licence). All those would make Go a good choice as a target of code generation, I think, maybe even better than the other options... So I am surprised I can't find anybody doing that already.
Would Go be a good choice for code generation? Can you point at existing projects doing so, or explain why there are none? Or even better, do you have experience with using the Go language as a backend? Are there any downside I am unaware of?
(I'm specifically interested in Go here. Don't just point at alternative backend options, there are questions answering that already.)
Upvotes: 6
Views: 1755
Reputation: 24828
There is this project called GoGo which is described to be a compiler written in Go and assembly for a subset of Go. Basically like a stripped down version of Go. I think you could start by modifying it to parse your own language.
I also remember a scripting-language-like subset of Go with its own compiler. I thought it was called GoScript but it seems like there are at least 3 different project with that same name so I wasn't able to find it.
I'd say do it and share your experience. Rather than a backend though, Go is going to be your intermediate language. At least that's what I think you want to do.
Cheers!
Upvotes: 0
Reputation: 91253
Upvotes: 6
Reputation: 6394
If you will use Go as backend for your language then your language will be very similar to Go.
You will be able to implement
You will no have
Go is very good language. I do not see what you can add to make a better language over Go.
Upvotes: -1