将代码转译为精简的C代码?

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

Transcompiling to bare bones C?

问题

在观看一些FOSDEM'14的演讲时,我发现这个演讲特别有趣。它是关于Go编程语言以及如何通过包访问编译器内部的内容。所以基本上你可以用Go编写一个程序,获取AST(抽象语法树)或者更低级别的SSA(静态单赋值),并对其进行分析,或者将其转换为其他形式(比如将其转译为JavaScript)。我觉得这非常有趣。我记得还有一些其他的语言也可以做到这一点:Vala(JavaScript转译器)和Boo(另一个JavaScript转译器)。一些语言提供将代码解析为AST的独立库,比如C/C++/ObjC的Clang,Ada的ASIS,或者Free Pascal的CodeTools,但这并不完全相同。

我正在考虑制作一个将Go转译为裸机C/C++的转译器(为了使其更适合操作系统开发,并且只是为了好玩),你认为这是个好主意吗?还有其他哪些语言可能更容易转译为裸机C/C++呢?

英文:

While watching some FOSDEM'14 presentations I found this one being particularly interesting. It is about the Go programming language and how it gives access to compiler's internal through packages. So basically you can write a program in Go that gets AST (abstract syntax tree) or more low level SSA (single static assignment) and analyze it, or transforms it into something else (like transcompiling it to JavaScript for example). I find it very interesting. I can remember a few other languages that do it: Vala (JavaScript transcompiler) and Boo another JavaScript transcompiler. Some languages provide parsing code to AST as a separate library, like Clang for C/C++/ObjC, ASIS for Ada, or CodeTools for Free Pascal, but it is not quite the same.

I'm thinking of making a Go transcompiler to bare bones C/C++ (to make it be more suitable for os development and just for the fun of it), do you think it is a good idea? Is there any other language that may be more easy to transcompile to bare bones C/C++?

答案1

得分: 1

我遇到的问题是垃圾回收 - 如果你将代码转译为纯C/C++,那么你要么必须自动插入正确的free()调用,要么你的代码将会在各个地方泄漏内存。

英文:

The problem that occurs to me is garbage collection - if you've transcompiled to pure C/C++ then you either have to automatically insert the correct free() calls or your code will leak memory all over the place.

huangapple
  • 本文由 发表于 2014年3月22日 03:27:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/22567848.html
匿名

发表评论

匿名网友

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

确定