谷歌的Golang是解释器还是编译器?

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

Is Google's Golang an interpreter or compiler?

问题

我一直在研究Golang,我发现它有一个编译器。
但是它是将Go编译成汇编级别的代码,还是只是将其转换为字节码,然后调用该编译?我的意思是,即使在PHP中,我们也能将其转换为字节码并获得更快的性能。
Golang是系统级编程和编译的替代品吗?

英文:

I have been researching Golang and I see that it has a compiler.
But is it compiling Go into assembly level code or just converting it into BYTECODES and then calling that compilation? I mean, even in PHP we are able to convert it into BYTECODES and have faster performance.
Is Golang a REPLACEMENT for system level programming and compiling ?

答案1

得分: 74

这实际上是一个编译器(实际上它嵌入了两个编译器),它可以生成完全自给自足的可执行文件。您不需要任何附加库或任何类型的运行时来在服务器上执行它。您只需要将其编译为目标计算机架构。

文档中:

> Go有两个官方编译器工具链。本文档重点介绍gc Go编译器和工具(6g、8g等)。有关如何使用GCC后端的更传统的编译器gccgo的信息,请参阅设置和使用gccgo。
>
> Go编译器支持三种指令集。对于不同架构的编译器质量有重要的差异。
>
> amd64(也称为x86-64);6g、6l、6c、6a
> 成熟的实现。编译器具有有效的优化器(寄存器分配器)并生成良好的代码(尽管gccgo有时可能做得更好)。
>
> 386(也称为x86或x86-32);8g、8l、8c、8a
> 与amd64端口相当。
>
> arm(也称为ARM);5g、5l、5c、5a
> 仅支持Linux二进制文件。使用较少,因此测试不如其他端口充分。
>
> 除了底层操作系统接口代码之类的东西,所有端口的运行时支持都是相同的,包括标记-清除垃圾收集器、高效的数组和字符串切片以及对高效的goroutine的支持,例如按需增长和收缩的堆栈。
>
> 编译器可以针对FreeBSD、Linux、NetBSD、OpenBSD、OS X(Darwin)和Windows操作系统进行目标设置。支持的完整组合列表在下面的环境变量讨论中列出。

在服务器上,您通常会针对amd64平台进行目标设置。

请注意,Go以编译速度而闻名。在部署我的服务器程序时,我不会在开发计算机上为不同的平台构建:我部署源代码,并直接在生产服务器上进行编译。自从Go1以来,我从未遇到过在一个平台上编译的代码在其他平台上无法编译的问题。

在Windows上,我在开发计算机上制作一个exe并简单地将此exe发送给从未安装过任何与Go相关的东西的人时没有任何问题。

英文:

This is really a compiler (in fact it embbeds 2 compilers) and it makes totally self sufficient executables. You don't need any supplementary library or any kind of runtime to execute it on your server. You just have to have it compiled for your target computer architecture.

From the documentation :

> There are two official Go compiler tool chains. This document focuses
> on the gc Go compiler and tools (6g, 8g etc.). For information on how
> to work on gccgo, a more traditional compiler using the GCC back end,
> see Setting up and using gccgo.
>
> The Go compilers support three instruction sets. There are important
> differences in the quality of the compilers for the different
> architectures.
>
> amd64 (a.k.a. x86-64); 6g,6l,6c,6a
> A mature implementation. The
> compiler has an effective optimizer (registerizer) and generates good
> code (although gccgo can do noticeably better sometimes).
>
> 386 (a.k.a. x86 or x86-32); 8g,8l,8c,8a
> Comparable to the amd64 port.
>
> arm (a.k.a. ARM); 5g,5l,5c,5a
> Supports only Linux binaries. Less widely used than
> the other ports and therefore not as thoroughly tested.
>
> Except for
> things like low-level operating system interface code, the run-time
> support is the same in all ports and includes a mark-and-sweep garbage
> collector, efficient array and string slicing, and support for
> efficient goroutines, such as stacks that grow and shrink on demand.
>
> The compilers can target the FreeBSD, Linux, NetBSD, OpenBSD, OS X
> (Darwin), and Windows operating systems. The full set of supported
> combinations is listed in the discussion of environment variables
> below.

On a server you'll usually target the amd64 platform.

Note that Go is well known for the speed of compilation. When deploying my server programs, I don't build for the different platforms on the development computer : I deploy the sources and I compile directly on the production servers. Since Go1 I never had a code compiling on one platform and not compiling on the other ones.

On Windows I had no problem in making an exe on my development computer and simply sending this exe to people never having installed anything Go related.

答案2

得分: 4

Go编译速度快,可以方便地进行垃圾回收,并具有运行时反射的能力。它是一种快速、静态类型、编译语言,感觉上像是一种动态类型、解释语言。

来源 - golang.org

英文:

> Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It's a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.

Source - golang.org

答案3

得分: 1

Golang是一种基于编译器的语言,可以轻松地在开发计算机上编译为任何目标系统,如Linux和Mac。

一个Golang项目一旦编译完成,就变成了一个自包含的可执行文件,可以在目标系统上运行,无需任何额外的东西。这是因为Golang编译器将您的代码转换为可在能够运行编译的C代码的系统上执行的字节码。

英文:

Golang is a compiler-based language, it can easily be compiled on the development computer for any targeted system such as linux and mac.

A golang project when have compiled turns to a self-sufficient executable and can be ran on the targeted system without anything additional. It's because the golang compiler turns your code into bytes ready to execute on a system which can run compiled c code.

huangapple
  • 本文由 发表于 2012年9月3日 21:37:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/12249364.html
匿名

发表评论

匿名网友

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

确定