作为我的编译器的后端,使用Go语言?

huangapple go评论76阅读模式
英文:

Go as a backend for my compiler?

问题

我想为自己的编程语言制作一个编译器。流行的后端选择似乎有C、Java、LLVM、JVM字节码、.Net字节码、gcc、汇编...在这里,我正在考虑将Go作为后端的可能性。

Go显然是一种快速的语言,具有垃圾回收和快速的编译时间。它还是可移植和免费的(BSD风格许可证)。我认为,所有这些都使得Go成为代码生成的一个很好的选择,甚至可能比其他选项更好...所以我很惊讶为什么我找不到已经有人这样做的情况。

Go是否是代码生成的一个好选择?你能指出已经存在的这样的项目,或者解释为什么没有这样的项目吗?或者更好的是,你有使用Go语言作为后端的经验吗?我是否有任何不知道的缺点?

(我在这里特别关注Go。不要只是指出替代的后端选项,已经有问题回答了这个问题。)

英文:

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

答案1

得分: 6

  • 我不知道有任何使用Go作为后端的语言项目。
  • Go并不是设计成编译器的后端或者IR。
  • Go足够底层(有点像C,除了垃圾回收器之外)以我个人的意见来说,可以作为一些语言/类似Go提供的语义的后端使用。
  • 很想了解你正在设计的语言的更多信息;-)
英文:
  • 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 作为我的编译器的后端,使用Go语言?

答案2

得分: 0

有一个名为GoGo的项目,被描述为用Go和汇编语言编写的编译器,用于Go的一个子集。基本上就像是一个简化版的Go。我认为你可以通过修改它来解析你自己的语言。

我还记得有一个类似脚本语言的Go子集,有自己的编译器。我以为它叫做GoScript,但似乎至少有3个不同的项目都有同样的名称,所以我找不到它。

我建议你去做并分享你的经验。不过,Go将成为你的中间语言,而不是后端。至少我认为这是你想做的。

祝好!

英文:

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!

答案3

得分: -1

如果您将使用Go作为后端语言,那么您的语言将非常类似于Go。

您将能够实现:

  • Go协程
  • Go通道
  • 垃圾回收

您将没有:

  • 线程

Go是一种非常好的语言。我不知道您能够添加什么来使其成为比Go更好的语言。

英文:

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.

huangapple
  • 本文由 发表于 2012年8月18日 17:36:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/12017504.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定