为什么 Go 源码包含很多 .go 文件?它们是如何编译的?

Why does Go source contain many .go files? How do they get compiled?

我想知道编译器是如何工作的!

https://github.com/golang/go 此来源包含 88% .go 文件。

所以这应该有另一个编译器来执行 .go 文件。

示例:https://github.com/golang/go/blob/964639cc338db650ccadeafb7424bc8ebb2c0f6c/src/go/ast/ast.go

Golang 使用什么编译器来生成最终的执行文件?!他们从哪里获得资源?

可能是 Golang 生成了一个 c 代码,然后使用 GCC 或...?

新更新

我不想要 go1.4 然后在使用 c.

github.com/golang/go 的 88% 来源是 .go 文件。在 Go Source 编译 .go 文件是什么?我想看看 Final GO 编译器?

https://github.com/golang/go/search?l=c

我认为这叫做 cg


意思是旧版本的Go编译器(1.4版)被用来编译新版本的Go编译器。???!

go-go1.4.3/src/go/token/token.go 这是 go token,lexer 并且写在 GO

FUNC: "func", GO: "go", GOTO: "goto", IF: "if", IMPORT: "import",

所以执行 .go 文件的主编译器在哪里?

go-go1.4.3/src/runtime/compiler.go

// Copyright 2012 The Go Authors.  All rights reserved.
package runtime
// Compiler is the name of the compiler toolchain that built the
// running binary.  Known toolchains are:
//
//  gc      The 5g/6g/8g compiler suite at code.google.com/p/go.
//  gccgo   The gccgo front end, part of the GCC compiler suite.
//
const Compiler = "gc"

go-go1.4.3/src/cmd/gc$制作

go tool dist install -v
make: go: Command not found
../../Make.dist:13: recipe for target 'install' failed
make: *** [install] Error 127

make gc 为什么需要 Go?!


上一版GO语言怎么用?!意思是这如何为跨平台生成输出?这使用生成代码到 C,然后使用 c 编译器?

根据 https://golang.org/doc/go1.5#implementation and https://www.infoq.com/news/2015/01/golang-15-bootstrapped ,Go 最初是用 C 实现的,但在 1.5 版本时成为自托管。 Bootstrapping 是用自身编译编译器的过程。 Go 开发人员编写了一个 C -> Go 转译器将原始 C 编译器转换为 Go,然后他们手动编辑了 Go 代码以使其符合地道。