我想知道 go 编译器是如何工作的!
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
Go Source 文件?我想看看 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 上
功能:“功能”,
走:“走”,
Go:“转到”,
如果如果”,
进口:“进口”,
那么主编译器在哪里执行.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 Language怎么用?!意思是这如何为跨平台生成输出?这使用生成代码到 C,然后使用 c 编译器?
最佳答案
根据 https://golang.org/doc/go1.5#implementation和 https://www.infoq.com/news/2015/01/golang-15-bootstrapped ,Go 最初是用 C 实现的,但在 1.5 版本时成为自托管的。 Bootstrapping 是用自身编译编译器的过程。 Go 开发人员编写了一个 C -> Go 转译器以将原始 C 编译器转换为 Go,然后他们手动编辑了 Go 代码以使其符合地道。
关于gcc - 为什么 Go 源码包含很多 .go 文件?它们是如何编译的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47734417/