Eldritch Conundrum
Eldritch Conundrum

Reputation: 8722

Go as a backend for my compiler?

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

Answers (3)

thwd
thwd

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

zzzz
zzzz

Reputation: 91253

  • I'm not aware of any language project using Go as a back-end.
  • Go is not designed to be a compiler back-end and or an IR.
  • Go is low level enough (bit like C except for e.g. the GC) to IMO be usable as a back-end for some languages/class of languages with semantics similar/comparable/close to what Go offers.
  • Would love to know more about the language you're designing ;-)

Upvotes: 6

Max
Max

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

  • go routines
  • go channels
  • GC

You will no have

  • threads

Go is very good language. I do not see what you can add to make a better language over Go.

Upvotes: -1

Related Questions