内置的源代码位置 [英] Built-In source code location

查看:77
本文介绍了内置的源代码位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Go的源代码中,我可以找到它们的实现 make



原来的代码搜索功能对于语言的这样一个中心功能来说几乎没有用,而且我也没有好的方法来确定我是否应该搜索C函数,Go函数或什么。



在未来,我怎么弄出这种东西而不诉诸于此? (即:教我钓鱼)

编辑
P.S.我已经找到了 http://golang.org/pkg/builtin/#make ,但那不像其他的go包,不包括到源代码的链接,大概是因为它在编译器域深处。

没有 make()等。简单地说,就是这样:
$ b


  1. go code: make(chan int)
  2. 符号替换: OMAKE

  3. 符号类型检查: OMAKECHAN

  4. 代码生成:运行时间* makechan

gc ,这是一个有趣的C语法分析器,根据 make 调用解析上下文(用于更简单的类型检查)。

这个转换是在 cmd / compile / internal / gc / typecheck.go 然后,取决于什么符号(例如, OMAKECHAN 用于 make(chan ...)),
CMD /编译/内部/ GC / walk.go 。在 OMAKECHAN 的情况下,这将是 makechan64 makechan


最后,当运行代码时,表示替换函数

你如何找到这个



我倾向于发现这种情况主要是想象在这个过程的哪个阶段可能发生这样的事情。在 make 的情况下,知道中没有
定义 make > pkg / runtime
(最基本的软件包),它必须在编译器级
上,并且很可能被替换为别的。



然后你必须搜索各种编译器阶段(gc,* g,* l),并及时找到
的定义。


Where in Go's source code can I find their implementation of make.

Turns out the "code search" functionality is almost useless for such a central feature of the language, and I have no good way to determine if I should be searching for a C function, a Go function, or what.

Also in the future how do I figure out this sort of thing without resorting to asking here? (i.e.: teach me to fish)

EDIT P.S. I already found http://golang.org/pkg/builtin/#make, but that, unlike the rest of the go packages, doesn't include a link to the source, presumably because it's somewhere deep in compiler-land.

解决方案

There is no make() as such. Simply put, this is happening:

  1. go code: make(chan int)
  2. symbol substitution: OMAKE
  3. symbol typechecking: OMAKECHAN
  4. code generation: runtime·makechan

gc, which is a go flavoured C parser, parses the make call according to context (for easier type checking).

This conversion is done in cmd/compile/internal/gc/typecheck.go.

After that, depending on what symbol there is (e.g., OMAKECHAN for make(chan ...)), the appropriate runtime call is substituted in cmd/compile/internal/gc/walk.go. In case of OMAKECHAN this would be makechan64 or makechan.

Finally, when running the code, said substituted function in pkg/runtime is called.

How do you find this

I tend to find such things mostly by imagining in which stage of the process this particular thing may happen. In case of make, with the knowledge that there's no definition of make in pkg/runtime (the most basic package), it has to be on compiler level and is likely to be substituted to something else.

You then have to search the various compiler stages (gc, *g, *l) and in time you'll find the definitions.

这篇关于内置的源代码位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆