Explain how packages are created in GO! How to create a package I’m aware of, I’m interested in how the MOST first package was created, say http, is it written in GO? Or it was written in another language, in general I don’t understand how it all happens at the initial stage, and I can’t find any articles anywhere ... If it was written on the GO, then where do all the functions come from, etc ...
1 answer
almost all golang is written in go (from version 1.5), with the exception of some "system" packages, for example the syscall package (there are low-level assembly inserts)
http written entirely in golang
up to 1.5 many functions were written in C, compiled into dynamic link libraries and called from go, like normal functions (in fact, this is still possible to do even with your own C libraries)
in fact, sooner or later you will come to the question, and how are compilers (translators, etc.) written on themselves and / or from scratch - the answer is:
Promotion of the compiler using the compiler of the existing language Creating a translator of the L language by the method of promotion involves performing certain steps.
- In the first step, the subset L0 is selected from the language L, which does not require much effort to implement, but is sufficient to write the translator itself.
- Then, using any existing language for this platform (for example, C), the compiler source code for L0 is compiled. Then in language L0 a translator is compiled for the language L0 itself. The translator executable file is created using the translator obtained in the first step. After that, the programmer has a translator L0, capable of processing its source code.
- Next, a gradual expansion of L0 to L begins: some previously unrealized L language feature is added, after which a new version of the translator creates a new one, and the newly added feature can be used in the translator for subsequent expansion of the language. This process is called promotion .
The number of steps can be reduced if, after compiling the translator L0 in C, immediately begin to compose the translator L on the subset L0.
- Much has become clear, but once again not against it will be convinced (I understood everything correctly). Translator is the conversion of a code into machine code or byte code, or into a code of another language. The compiler is the translation of the code mainly into machine code. An interpreter is a translation of the code on the fly (without creating an executable file). Further, the GO compiler was created in another language (C ++) (all its functions, etc ...), after the compiler became, say, powerful, then this GO compiler (written in C ++) compiled the compiler written on GO for GO, right? - bsbak
- Yes, everything is so, only used C (without ++). Many compilers created the same way, not just go. - Darigaaz