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.
The source for python 2.7 itself can be found at http://hg.python.org/cpython. Other versions of python have had their source imported onto Launchpad. You can see them here.
Since Python is open source you can read the source code. To find out what file a particular module or function is implemented in you can usually print the __file__ attribute. Alternatively, you may use the inspect module, see the section Retrieving Source Code in the documentation of inspect .
Everything in python is object. Python stores object in heap memory and reference of object in stack. Variables, functions stored in stack and object is stored in heap.
There is no make()
as such. Simply put, this is happening:
make(chan int)
OMAKE
OMAKECHAN
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With